Code seems perfect but doesn't function

 

Hello,

Thanks for your time! In my code, I want to make a variable (greenlineprice) equal to the highest point of the last 6 bars, but only when the conditions are met

I used a variable (choice) to serve as a signal to my Switch&Case on when the conditions are met. The problem I have now is, the "choice" variable does not react or change values when the conditions are met. 

It is important that the "choice" variable reacts so my code will know when to make greenlineprice equal to the highest point of the last 6 bars.

Please help. 

Files:
 
jidebranco :

Hello,

Thanks for your time! In my code, I want to make a variable (greenlineprice) equal to the highest point of the last 6 bars, but only when the conditions are met

I used a variable (choice) to serve as a signal to my Switch&Case on when the conditions are met. The problem I have now is, the "choice" variable does not react or change values when the conditions are met. 

It is important that the "choice" variable reacts so my code will know when to make greenlineprice equal to the highest point of the last 6 bars.

Please help. 

You are making a gross mistake: you CREATE A HANDLE OF THE INDICATOR ON EACH TICK !!!

Check out the help: iMA - the handle is created in OnInit. An example of getting indicator data in an advisor: Creating an iMA indicator handle, getting indicator values

 
Vladimir Karputov:

You are making a gross mistake: you CREATE A HANDLE OF THE INDICATOR ON EACH TICK !!!

Check out the help: iMA - the handle is created in OnInit. An example of getting indicator data in an advisor: Creating an iMA indicator handle, getting indicator values

Thanks Vladmir. I'm no pro yet. I changed the strategy to be a lot less complex but still does not work. I want arrows printed on my chart anytime a trade opens (green arrow for buy trade, red arrow for sell trade). I have attached the code. I will appreciate it if you, or anyone, could take a look and tell me what the problem could be. 

Thanks!

Reason: