data1 order based on data2 trigger  [SOLVED]

Questions about MultiCharts and user contributed studies.
moreno
Posts: 22
Joined: 29 May 2019
Has thanked: 19 times

data1 order based on data2 trigger

Postby moreno » 09 Jul 2020

Hi,
It looks simple but something doesn't work for me while trying to execute orders in chart1 (data1) based on chart2 (data2) trigger condition...
the trigger/condition is 3MA cross on chart2, if condition met sellshort chart1. NOTHING HAPPENS, the condition doest met...
while the reference indicator show the condition met more then 10 times...
the code as follows:

Code: Select all

inputs: FastLength( 4 ), MedLength( 9 ), SlowLength( 18 ) ; variables: price(Close), price2(close,data2), MyFast( 0,data2 ), MyMed( 0,data2 ), MySlow( 0,data2 ); MyFast = AverageFC( close, FastLength )data2 ; MyMed = AverageFC( close, MedLength )data2 ; MySlow = AverageFC( close, SlowLength )data2 ; Condition1 = price2 > myfast and myfast > MyMed and MyMed > MySlow ; condition2 = CurrentBar > 1 and Condition1 and Condition1[1] = false; if condition2 then sellshort ("short") next bar at market;
what may be the problem? where am I wrong?

Mydesign
Posts: 177
Joined: 15 Feb 2017
Has thanked: 32 times
Been thanked: 39 times

Re: data1 order based on data2 trigger  [SOLVED]

Postby Mydesign » 09 Jul 2020

Hi,

Try to add this line:

Code: Select all

Price2 = Close Data2 ;
You may eventually also add this condition:

Code: Select all

If BarStatus(2) = 2 then begin
Also, make sure that Data1 is a higher (faster) resolution than Data2.
Last edited by Mydesign on 09 Jul 2020, edited 1 time in total.

moreno
Posts: 22
Joined: 29 May 2019
Has thanked: 19 times

Re: data1 order based on data2 trigger

Postby moreno » 09 Jul 2020

thanks Mydesign
the code

Code: Select all

Price2 = Close Data2 ;
works great!


Return to “MultiCharts”