NexusFi: Find Your Edge


Home Menu

 





Another CrossBelow/Above question from newbie


Discussion in NinjaTrader

Updated
    1. trending_up 3,620 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
Search this Thread

Another CrossBelow/Above question from newbie

  #1 (permalink)
Al2010
 
Posts: 50 since Oct 2010
Thanks Given: 36
Thanks Received: 10

Hello,
I wrote a simple program that draws arrows whenever the Stochastic crosses above 20 or below 80. But sometimes the Stoch. completes the cycles before crossing 20 or 80. Unfortunately I'm not smart enough to write smth more complicated and need help with this if possible please. I do not know if this is too much to ask. Please let me know if this is the issue.
The idea is simple - to get a single arrow per cycle. Currently the program draws the arrows whenever the Stoch crosses 20 then 30, 40 etc... But what I want is to check for all crosses, e.g. CrossAbv 20, 30, 40... and if either one is true then draw the arrow and disregard the rest of the crosses. Below is the simple test code I wrote, which works lk OR, e.g. drawing arrows if cross abv 20 or 30, or 40... It would work if the Stoch. completes the cycle before crossing below 20% line then reverses somewhere around 25% and keep rising. But again, it would draw the arrows at 30, 40... But I want only one arrow per cycle, e.g. if it reverses at 25 then check for crosses above 25 and if cross abv 30 = true draw arrow and disregard the rest of the checks.

private int crsAbvCheck = 0;
bool crsAbv20 = false;
bool crsAbv30 = false;
bool crsAbv40 = false;
bool crsAbv50 = false;

OnBarUpdate....

if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 20, 1))
{
crsAbv20 = true; crsAbvCheck = 20;
}
else if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 30, 1))
{
crsAbv30 = true; crsAbvCheck = 30;
}
else if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 40, 1))
{
crsAbv40 = true; crsAbvCheck = 40;
}
else if (CrossAbove(Stochastics(periodD, periodK, smooth).K, 30, 1))
{
crsAbv50 = true; crsAbvCheck = 50;
}
else
{
crsAbv20 = false; crsAbv30 = false; crsAbv40 = false; crsAbv50 = false; crsAbvCheck = 0;
}

if (crsAbv20 || crsAbv30 || crsAbv40 || crsAbv50) { Print("Cross abv = " +crsAbvCheck+ "---Time:......"+Time[0]); }

I do not know how to write a code that would draw arrow for the first cross and would disregard the rest.
Another thing that comes to mind but I do not have enough skills to implement this is how to check the MACD cross if Stoch. cross returns false, which sounds simple....
Thank you very much.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Quant vue
Trading Reviews and Vendors
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
How to apply profiles
Traders Hideout
 
  #3 (permalink)
 bukkan 
Calcutta, India
 
Experience: Intermediate
Platform: ArthaChitra
Posts: 278 since Jun 2009
Thanks Given: 161
Thanks Received: 271


i really didnt get what exactly you want, but your logic is wrong.

say the current stochastic value is 55.

now your code first checks whether the same is greater than 20. and ya sure it is, thus it skips the rest of the elseif code.

you got to code it this way

if (stochastic > 20 && stochastic <30)
{
//do something
}
else if (stochastic > 30 && stochastic < 40)
{
//do something
}

and likewise. hope you got the point. sorry for the crude code.

Reply With Quote
Thanked by:
  #4 (permalink)
Al2010
 
Posts: 50 since Oct 2010
Thanks Given: 36
Thanks Received: 10


bukkan View Post
i really didnt get what exactly you want, but your logic is wrong.

say the current stochastic value is 55.

now your code first checks whether the same is greater than 20. and ya sure it is, thus it skips the rest of the elseif code.

you got to code it this way

if (stochastic > 20 && stochastic <30)
{
//do something
}
else if (stochastic > 30 && stochastic < 40)
{
//do something
}

and likewise. hope you got the point. sorry for the crude code.


Thank you very much for you reply.
I think this will still work as OR. If the Stoch is below 20 and rising then if the Stoch > 20 && < 30 then cross abv 20 = true-draw arrow up. If Stoch. keeps rising and > 30 && < 40 then cross abv 30=true... Which will draw arrows first @20 then @30...@40... I maybe wrong but I don't think the else if will be skipped as you suggested. Or in case the Stoch is above 30 and rising the arrows will be drawn @ 30 and @40... But how to stop drawing arrows at the first cross, whichever cross this would be-20-30 or 40...? Then the next cross should be checked only when the prev. cycle is complete. This is the problem I cannot figure out.

Here is the example: the first cross was @20-draw arrow up at 20. Then the Stoch keeps rising abv 50 or higher. In this case only one arrow @20 should be drawn and crosses abv 30-40 should be disregarded.

Another example: In my code i have all three checks-if cross abv 20-30 or 40 true then do smth. The stoch is below 20 and rising - cross abv 20=true-then draw arrow up. Then after cross abv 20 it continues rising above 50-55. Then it reverses and falling and reached 27. Then it reverses back up @27 (creating higher low - the first low was below 20) and keeps rising. In this case the previous cross abv 20 and the cross above 30 are true and both arrows should be drawn at 20 and 30. Bcs to me the Stoch. completed the cycle going above 50 then it reverses back down and started the new cycle up @ 27. The cross above 40 should be disregarded - no arrow @40.



Thank you very much.

Reply With Quote




Last Updated on December 4, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts