Strategy Development

Posted By: MINER

Strategy Development - 12/11/18 12:43

Hello community,
I have a script as shown below, i intend the script to be using current price and an indicator(EMA) in my case. The barperiod is 1440. i would like the script to enter a trade without waiting for the current running bar to be closed as it is not using priceclose but the current price. i would also like the script to exit the trade when the indicator crosses the price on opposite direction. the script is below and attached is what i intend the script to be doing. The white line is the indicator whereas the other line is the price(AUDUSD) in my case. Kindly help on how to update the script to produce the desired script....

I like Zorro Though, ...


function run()
{
StartDate = 2011;
EndDate = 2018;
set(TICKS);
Lots = 300;
BarPeriod = 1440;
LookBack = 150;
MaxLong = 1;
MaxShort = 1;

Stop = 50*PIP;
Trail = 1.5*ATR(14);
//TrailLock = 1;


vars EMA7 = series(EMA(Close, 7));
vars Price = series(price());

if(Price[0] > EMA3[0])
enterLong();
//if(Close[0] < Close[2])
//exitLong()

if(Price[0] < EMA3[0])
enterShort();
//if(Close[0] Close[])
//exitShort

plot("EMA3", EMA3[0], 0, BLUE);

set(PLOTNOW);
PlotWidth = 1200;
PlotHeight1 = 350;
}

Attached picture PRICE AND INDICATOR.PNG
Posted By: AndrewAMD

Re: Strategy Development - 12/11/18 12:52

You're using run(), which only operates on the close of a bar.
https://zorro-project.com/manual/en/run.htm

For tick-based entries (as opposed to bar-based), use tick().
https://zorro-project.com/manual/en/tick.htm

Also, see here for the definition of price():
https://zorro-project.com/manual/en/price.htm

Basically, this is not MT4. laugh
Posted By: MINER

Re: Strategy Development - 12/11/18 13:00

Thank once more AndrewAMD, let me implement that and will get back to you.
Posted By: MINER

Re: Strategy Development - 12/11/18 13:22

Andrew please can you guide me on how to do it because my solution is generating error 041: invalid call in TMf! and error 111: crash in tick() at bar 67......
have just replace run with tick and this is reason for these errors.

illustrate to me with an example please.....this is using a lot of my brain.
Posted By: AndrewAMD

Re: Strategy Development - 12/11/18 15:55

You cannot use series() in tick(). You can only use series() in run().
https://zorro-project.com/manual/en/series.htm

You are attempting to do metatrader-style coding, which I discourage. These issues are discussed in the manual:
https://zorro-project.com/manual/en/conversion.htm

Quote:
"Meta"-Trader 4 (MQ4)

This is a popular platform for private traders and provided by most brokers. The MQ4 script language of its "Expert Advisors" (EAs) is based on C, which would theoretically allow easy conversion to Zorro's lite-C. Unfortunately, MQ4 has many issues that make "Expert Advisors" a lot more complex and difficult to handle than scripts of other platforms.

The MQ4 main script runs at every tick. This means that the last price candle is normally incomplete, so indicators in EAs return a different value than the same indicators in other platforms. For fixing this, the EA must check if the candle is complete, or the indicator must be shifted so that its last value is from the previous candle. Trades are not managed by the platform, but must be managed by code in the script. Series are not natively supported, but emulated with loops and functions. Indicators often produce different results in MQ4 than in other platforms because the MQ4 standard indicators do not use their standard algorithms, but special MQ4 variants. Time zones and account parameters are not normalized, so EAs must be individually adapted to the broker. To complicate matters further, MQ4 does not use common trade units such as lots and pips, but calculates with "standard lots" and "points" that need to be multiplied with account-dependent conversion factors. Most code in an EA is therefore not used for the trade algorithm, but for working around all those problems. This results in the long and complex 'spaghetti code' that is typical for EAs.

Posted By: MINER

Re: Strategy Development - 12/12/18 08:10

Thank you, i appreciate your information @AndrewAMD
Posted By: OptimusPrime

Re: Strategy Development - 12/13/18 01:08

Thank you AndrewAMD
© 2024 lite-C Forums