NexusFi: Find Your Edge


Home Menu

 





Does MRO function automatically cut off bars?


Discussion in TradeStation

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




 
Search this Thread
  #1 (permalink)
minoschan
Shenzhen China
 
Posts: 3 since Aug 2019
Thanks Given: 1
Thanks Received: 0

Hey guys, I'm a newbie here, and please forgive me if I'm asking a silly question. And yes I live in China, I'll try my best to describe my problem in Chinglish.

I tried to set up an indicator like errr...price diversion. My code is like this:

Variables:
double DIFF(0), double DEA(0), double MyMACD(0),MACD_GCross(False),
MACD_DCross(False), int BarsUp(0);

DIFF = XAverage(Close, 12) - XAverage(Close, 26);
DEA = XAverage(DIFF, 9);
MyMACD = 20*(DIFF-DEA); //It was multiplied by 20 for convenience only, actually it should be 2hi
Plot1(DIFF, "DIFF", White);
Plot2(DEA, "DEA", Yellow);
Plot3(MyMACD, !("MyMACD")); //Displayed in histogram
if MyMACD > 0 then
SetPlotColor(3, Red)
else if MyMACD < 0 then
SetPlotColor(3, Cyan);

MACD_GCross = DIFF cross over DEA;
MACD_DCross = DIFF cross under DEA;
BarsUp = MRO(MACD_GCross, 200, 1) + 1; //Calculating the bars since the last time DIFF crossed over DEA, in a 200- bar length

...


So here's the problem. It was verified all OK. But when I add it to my bars chart, the first 200 verticle lines plotted(i.e. MyMACD Variable) was automatically removed from the chart. If I remove the "BarsUp = MRO(MACD_GCross, 200, 1) + 1;" sentence, it was plotted right. Anyone have any idea what's wrong with my code? What should I do if I wanna keep all the lines without removing the MRO function, which I think is a very handy function for newbies like me. I Any help is appreciated.

Best Regards


Attached Thumbnails
Click image for larger version

Name:	WX20190830-194407@2x.png
Views:	275
Size:	795.9 KB
ID:	274220  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Rubios Good News Within Hours and the 30-Day Math: Why H …
Prediction Markets & Event Contracts
Four New E-mini Futures Launch June 29 -- Russell 3000, …
Emini and Emicro Index
Would a node-based workflow for automated trading be useful?
Traders Hideout
Six Days to Kickoff: World Cup Prediction Markets Hit $1 …
Prediction Markets & Event Contracts
Ninjatrader users - good CONNECTIONs post and article fr …
NinjaTrader
 
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

minoschan,

this is likely caused by the maximum number of bars that Tradestation requires for a study.
You can read more about it here:
Maximum Number of Bars Study Will Reference Setting

Regards,

ABCTG


Follow me on X Reply With Quote
  #3 (permalink)
minoschan
Shenzhen China
 
Posts: 3 since Aug 2019
Thanks Given: 1
Thanks Received: 0


Thanks for the quick tip, ABCTG. I was googling how to use the Maxbarback and will try to figure it out by myself.
I'd like to bring forward one more question without adding a new thread. On many occasions, when I try to plot some lines for my variables, TS won't allow me to plot from the first bar(i.e. the first in history of a stock). I tried these code:
"Value1=10.01;
Plot1(Value1, "Value1")
;
And it plotted the value from the SECOND bar, which should be BarNumber 1 I suppose.
I tried "Value 1 = Close;", it also began from the second bar(BarNumber 1). So what's the usual way to reference the REAL first bar, and plot the Values exactly from the beginning?
P.S. Certain functions like MACD also IGNORED the first Bar. The first Bar arguably has no 'previous EMA value', but the code actually presumes the second Bar Price to be the 'previous value' for the third Bar. It used the same method, like many other platforms, except it just IGNORED the first Bar.


Reply With Quote
  #4 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,448 since Apr 2013
Thanks Given: 494
Thanks Received: 1,643

minoschan,

I am not sure you can get around this platform behavior. If starting at the very first bar of a session is important you could load one additional session and start your code logic on the first bar of the second session.

Regards,

ABCTG



minoschan View Post
Thanks for the quick tip, ABCTG. I was googling how to use the Maxbarback and will try to figure it out by myself.
I'd like to bring forward one more question without adding a new thread. On many occasions, when I try to plot some lines for my variables, TS won't allow me to plot from the first bar(i.e. the first in history of a stock). I tried these code:
"Value1=10.01;
Plot1(Value1, "Value1")
;
And it plotted the value from the SECOND bar, which should be BarNumber 1 I suppose.
I tried "Value 1 = Close;", it also began from the second bar(BarNumber 1). So what's the usual way to reference the REAL first bar, and plot the Values exactly from the beginning?
P.S. Certain functions like MACD also IGNORED the first Bar. The first Bar arguably has no 'previous EMA value', but the code actually presumes the second Bar Price to be the 'previous value' for the third Bar. It used the same method, like many other platforms, except it just IGNORED the first Bar.


Follow me on X Reply With Quote
Thanked by:
  #5 (permalink)
minoschan
Shenzhen China
 
Posts: 3 since Aug 2019
Thanks Given: 1
Thanks Received: 0

Tried to modify the XAverage function. And it works better now. Thought of a way to work around the manner of TS, which means I'll have to write some more code myself. Thanks ABCTG for your help and patience!

Regards,


Reply With Quote




Last Updated on September 4, 2019


© 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