NexusFi: Find Your Edge


Home Menu

 





Can you build a strategy to reference another chart window? MC.NET


Discussion in MultiCharts

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




 
Search this Thread

Can you build a strategy to reference another chart window? MC.NET

  #11 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

BrianBacchus,

you are correct that when you loop over the last 2500 bars to populate the array, you will run into the MaxBarsBack limitation again.
One approach to prevent this could be to only store the close for the current bar in your array. Then on the next bar you increment the array index and store the new bar's close in the array (using the new index) etc.. You do this until your array index reaches the number of values that you want to store (2500) in your case and at that moment you'd reset the index to 0 and store the new value (while overwriting the oldest value in the array).
Once you have 2500 values in your array you can perform the other calculations.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Increase in trading performance by 75%
The Elite Circle
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
33 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
HumbleTraders next chapter
11 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #12 (permalink)
 BrianBacchus 
Las Vegas
 
Experience: Intermediate
Platform: MultiCharts .NET
Trading: CL
Posts: 26 since Oct 2015
Thanks Given: 7
Thanks Received: 37

Just wanted to say thanks to everyone that helped in this thread. Finally figured out exactly how to do this, so to anyone curious here's precisely how you get around the maxbarsback limitation:

 
Code
double[] newBarsClose;

//under Create:
newBarsClose = new double[length + 1];

//under StartCalc:

newBarsClose[0] = Bars.Close[0]

//under CalcBar:

Array.Copy(newBarsClose, 0, newBarsClose, 1, length);
newBarsClose[0] = Bars.Close[0];
At that point you substitute newBarsClose[x] in the same way you'd use Bars.Close[x].

I haven't fully tested it, but it looks like it might cause indicators to calculate faster as well.

UPDATE: The indicator using the array loaded on a 1 tick chart (405,000 bars) in ~15 seconds. Standard indicator using Bars.Close[x] loaded on the same chart in ~25 seconds.

Started this thread Reply With Quote
Thanked by:
  #13 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627


BrianBacchus,

good job. You might be able to speed things up even further by not copying the entire array each time, but by just overwriting the respective index with the new value on every bar.

Something along the lines of this should work for your one tick chart:
 
Code
//under Create:
newBarsClose = new double[length];

//under CalcBar:
newBarsClose[(Bars.CurrentBar-1) % length] = Bars.Close[0];
On the first bar index 0 is filled (because 0 % 2500 = 0) and each new bar will be stored in the next index (for example on bar two: 1 % 2500 = 1 etc.). Assuming a length of 2500 on bar 2501 the index "(Bars.CurrentBar-1) % 2500" will evaluate to 0 again and overwrite the first index.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #14 (permalink)
 BrianBacchus 
Las Vegas
 
Experience: Intermediate
Platform: MultiCharts .NET
Trading: CL
Posts: 26 since Oct 2015
Thanks Given: 7
Thanks Received: 37


ABCTG View Post
BrianBacchus,

good job. You might be able to speed things up even further by not copying the entire array each time, but by just overwriting the respective index with the new value on every bar.

Something along the lines of this should work for your one tick chart:
 
Code
//under Create:
newBarsClose = new double[length];

//under CalcBar:
newBarsClose[(Bars.CurrentBar-1) % length] = Bars.Close[0];
On the first bar index 0 is filled (because 0 % 2500 = 0) and each new bar will be stored in the next index (for example on bar two: 1 % 2500 = 1 etc.). Assuming a length of 2500 on bar 2501 the index "(Bars.CurrentBar-1) % 2500" will evaluate to 0 again and overwrite the first index.

Regards,

ABCTG

I gave this a try and it does something kind of weird, it gives the first value, repeats it until 2500th bar (tick) then repeats another value for the rest of the chart.

My copy method works great for indicators but I'm running into all sorts of silliness trying to use it in a strategy as I keep getting "destination index is not long enough" errors.

Started this thread Reply With Quote
  #15 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

BrianBacchus,

I am afraid I could only guess without seeing the entire code.

Does the error message actually state "destination index is not long enough" or destination arrayis not long enough" and how often does it come up?

Regards,

ABCTG


BrianBacchus View Post
I gave this a try and it does something kind of weird, it gives the first value, repeats it until 2500th bar (tick) then repeats another value for the rest of the chart.

My copy method works great for indicators but I'm running into all sorts of silliness trying to use it in a strategy as I keep getting "destination index is not long enough" errors.


Follow me on Twitter Reply With Quote




Last Updated on June 6, 2018


© 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