NexusFi: Find Your Edge


Home Menu

 





Need help for currentbar being reset to 1 of my program


Discussion in EasyLanguage Programming

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




 
Search this Thread

Need help for currentbar being reset to 1 of my program

  #1 (permalink)
mzhawen
Guangzhou,China
 
Posts: 6 since Jan 2017
Thanks Given: 0
Thanks Received: 0

I wrote a program for find top and bottom of the price. But I find it a problem. After few bars, the program will be restarted, the currentbar will be reset to 1. Please anybody help me, what's the problem of my program as follow:

Var: LastDingNo(1),LastDiNo(0),LastDingBarsBack(0),LastDiBarsBack(0);

LastDingBarsBack = CurrentBar - LastDingNo + 1;
LastDiBarsBack = CurrentBar - LastDiNo + 1;


Once
Begin
Print("Strat");
End;

Print("--------------------");
Print(ELDateToString(Date));
Print("CurrentBar",CurrentBar);

If (LastDingNo>LastDiNO) and (LastDingBarsBack>=5) and Low=Lowest(Low,LastDingBarsBack) then
Begin
Plot1[LastDiBarsBack](High[LastDiBarsBack],"FenXing");
LastDiNo = CurrentBar;
Print("Condition1");
Print("LastDing",LastDingNo);
Print("LastDi",LastDiNo);
Print("LastDingBarsBack",LastDingBarsBack);
Print("LastDiBarsBack",LastDiBarsBack);
End;


If (LastDiNo>LastDingNO) and Low=Lowest(Low,LastDiBarsBack) then
Begin
LastDiNo = CurrentBar;
Print("Condition2");
Print("LastDing",LastDingNo);
Print("LastDi",LastDiNo);
Print("LastDingBarsBack",LastDingBarsBack);
Print("LastDiBarsBack",LastDiBarsBack);
End;


If (LastDiNo>LastDingNO) and (LastDiBarsBack>=5) and High=Highest(High,LastDiBarsBack) then
Begin
Plot1[LastDiBarsBack](Low[LastDiBarsBack],"FenXing");
LastDingNo = CurrentBar;
Print("Condition3");
Print("LastDing",LastDingNo);
Print("LastDi",LastDiNo);
Print("LastDingBarsBack",LastDingBarsBack);
Print("LastDiBarsBack",LastDiBarsBack);
End;


If (LastDingNo>LastDiNO) and High=Highest(High,LastDingBarsBack) then
Begin
LastDingNo = CurrentBar;
Print("Condition4");
Print("LastDing",LastDingNo);
Print("LastDi",LastDiNo);
Print("LastDingBarsBack",LastDingBarsBack);
Print("LastDiBarsBack",LastDiBarsBack);
End;

And the following picture is the printlog:

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Quantum physics & Trading dynamics
The Elite Circle
MC PL editor upgrade
MultiCharts
Trade idea based off three indicators.
Traders Hideout
Cheap historycal L1 data for stocks
Stocks and ETFs
 
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629


mzhawen,

from your description it sounds like the Max Bars for the study are set to automatic and when TS encountered a situation were it had to look back further than this setting, it reloaded the code.

About the Maximum Bars Back Setting
Maximum Number of Bars Study Will Reference Setting

I would try to use a specific value instead of automatic and make sure that this value is higher than the highest values your variables for "LastDingBarsBack" and "LastDiBarsBack" can have.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
mzhawen
Guangzhou,China
 
Posts: 6 since Jan 2017
Thanks Given: 0
Thanks Received: 0

ABCTG,

Thanks for your analysis and reply.

I try to comstomized the MaxBarsBack with different value, but it seems work like the same.
Do you have any information for TS operation mechanism, i would like to learn it and try to analyze this problem.

Thanks again for your kindness.

mzhawen

Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

mzhawen,

what values did you try?

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #6 (permalink)
mzhawen
Guangzhou,China
 
Posts: 6 since Jan 2017
Thanks Given: 0
Thanks Received: 0

ABCTG,

I had tried 1 to 10,20,30,50,100, but the printlog stays the same. Actually it stays the same while the MaxBarsBack is "Auto-detect".
To observe the MaxBarsBack, I add "Print(MaxBarsBack)" in my program, it firstly appear as "1". Every time the currentbar changes to 1, the MaxBarsBack changes.

The attched is the printlog.

Regards,

mzhawen

printlog.txt

Reply With Quote
  #7 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629

mzhawen,

when you say "Every time the currentbar changes to 1, the MaxBarsBack changes. ", it's actually the other way around. The change in MaxBarsBack causes the reload, which in turn makes the code start over and prints currentbar 1 again.
You need to find out where you look back further than the MaxBarsBack in your code.

It's likely caused by either or both of these variables
 
Code
LastDingBarsBack = CurrentBar - LastDingNo + 1;
LastDiBarsBack = CurrentBar - LastDiNo + 1;
To check this, you could test if you get the same behavior when you limit the value that these variables can have to 10 (for example) or keep them static at 10 and use a MaxBarsBack setting of 50.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
  #8 (permalink)
mzhawen
Guangzhou,China
 
Posts: 6 since Jan 2017
Thanks Given: 0
Thanks Received: 0

ABCTG,

I am a bit following.
And yes there's some code look back further than MaxBarsBack, more exactly, further than that of CurrentBar.

I will try to modify my code, later share you the result.

Thanks a lot for your favor!

Regards,

mzhawen

Reply With Quote




Last Updated on January 25, 2017


© 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