NexusFi: Find Your Edge


Home Menu

 





Loop to Record Average Change in Bars


Discussion in MultiCharts

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




 
Search this Thread
  #1 (permalink)
 JHall65 
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
Posts: 23 since Apr 2013
Thanks Given: 3
Thanks Received: 2

I am trying to record the average difference in the highs of the last few bars. This is the code I have:

For Counter = BarsToAvg DownTo 1 Begin
BarDevi = (High[Counter] - High[Counter+1]);
TotalDevi = HighDevi + HighDevi[1];
Print(TotalDevi:6:6)
Print(Counter);
End;

Print(High[1]-High[2]:6:6);
Print(High[2]-High[3]:6:6);
Print(High[3]-High[4]:6:6);
Print(High[4]-High[5]:6:6);



The output I get for this is:
0.000000
4.00
0.000000
3.00
0.000000
2.00
0.000000
1.00
0.002500
0.000500
0.000700
0.000700

Why don't my numbers match up? Any help is greatly appreciated!


Started this thread Reply With Quote

 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
The Pivot Point 113.6³ — Navigating the Prediction of …
26 thanks
Sober Journey With S&P
16 thanks
The Confluence Meter: A Multi-Layered Signal Framework B …
11 thanks
NT8 color choices
10 thanks
Volume Indicators
7 thanks
  #2 (permalink)
kl610
London UK
 
Posts: 1 since Oct 2013
Thanks Given: 0
Thanks Received: 0

BarDevi = (High[Counter] - High[Counter+1]);
TotalDevi = HighDevi + HighDevi[1];

You was using BarDevi, then using HighDevi.
Should they be same? Otherwise BarDevi would be meaningless in this indicator.


Reply With Quote
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,447 since Apr 2013
Thanks Given: 493
Thanks Received: 1,639


You are printing TotalDevi, which in your code piece is always 0.
I guess the summation for TotalDevi should look something like in this code.
Set it to 0 before the loop and then with each loop add BarDevi to it.

 
Code
		TotalDevi = 0;
		For Counter = BarsToAvg DownTo 1 Begin
			BarDevi = (High[Counter] - High[Counter+1]);
			TotalDevi = TotalDevi + BarDevi;
			
			Print("High["+NumToStr(Counter, 0)+"]-High["+NumToStr(Counter+1, 0)+"]: ", BarDevi:6:6);
			Print("TotalDevi: ", TotalDevi:6:6);
		End;

		Print("High[1]-High[2]: ", High[1]-High[2]:6:6);
		Print("High[2]-High[3]: ", High[2]-High[3]:6:6);
		Print("High[3]-High[4]: ", High[3]-High[4]:6:6);
		Print("High[4]-High[5]: ", High[4]-High[5]:6:6);
Regards,
ABCTG


Follow me on X Reply With Quote




Last Updated on October 25, 2013


© 2026 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 - Downloads - Top
no new posts