Delay in script execution

Posted By: MINER

Delay in script execution - 11/20/18 11:20

i have an issue i would like to be clarified with, i have for example a script on SMA but whenever a cross happens between the MAs Zorro delays to enter or close trade with several hours, im using mt4 platform so i can clearly monitor when the crosses happen. How can i solve this such that zorro responds immediately as per trading script when trading rules are met.
Posted By: AndrewAMD

Re: Delay in script execution - 11/20/18 12:45

Do you mean **before** you have a fully-formed bar? If so, you can use tick() instead of run(). You will need to calculate the unfinished indicator outputs.

I should note: MQL's first fully formed bar is bar [1], whereas Zorro's first fully formed bar is bar [0].

Quote:
Zorro delays to enter or close trade with several hours
Just to confirm, what bar period are you using?
Posted By: Dalla

Re: Delay in script execution - 11/20/18 16:20

Post code 😀
Posted By: MINER

Re: Delay in script execution - 11/21/18 08:48

This is the code and below is an attachment of mt4 chart indicating the recent trades executed by the same script, Note that the recent trades were not triggered by a cross of the SMAs but something else im not sure of. Kindly assist me perfect this.....
function run()
{


StartDate = 2005;
BarPeriod = 60;
Lots = 30;
MaxLong = 1;
MaxShort = 1;
//EntryTime =

vars Close = series(priceClose());
vars SMAFast = series(SMA(Close, 5));
vars SMASlow = series(SMA(Close, 15));


if(crossOver(SMAFast, SMASlow))
enterLong();

else if(crossUnder(SMAFast, SMASlow))
enterShort();

Stop = 5 * ATR(100);
Trail = 4*ATR(100);

for(open_trades)
if(TradeIsOpen && !TradeIsPool && TradeProfit > 0) {
TradeTrailLock = 0.80; // 80% profit (minus trade costs)
if(TradeIsShort)
TradeTrailLimit = max(TradeTrailLimit,TradePriceClose);
else
TradeTrailLimit = min(TradeTrailLimit,TradePriceClose);
}



}
Posted By: MINER

Re: Delay in script execution - 11/21/18 09:23

The below attachment is the exact mt4 chart the script is trading on, the white lines cutting across the chart indicate entry and closure of trades which is not happening as soon as the crossovers and crossunders happen, the most recent trades entered by the script are the blue dotted line which indicates a buy trade and ended up losing, what triggered this trade......the next red dotted line indicates a sell trade and still ended up losing, again what triggered this trade? ....after 050:00 there was another buy trade entered by the script and so far is a losing trade as you can see in the chart & still i can't figure out what triggered it since no cross happened....help me solve this please.

Attached picture chart 2.PNG
Posted By: MatPed

Re: Delay in script execution - 11/21/18 10:06

Hi,
in order to investigate this I recommend to print the value of the 2 sma right before entering the trade.
On top of this I guess you have to set Stop and Trail before entering the trade if you want set them in the proper way. HtH
Ciao
Posted By: MINER

Re: Delay in script execution - 11/21/18 10:33

Thank you Matped, do you mean the price values?....if not please kindly elaborate on printing the values of 2 sma right before entering the trade ......
Posted By: MatPed

Re: Delay in script execution - 11/21/18 10:42

Yes value of price, and of the 2 before enterLong and enterShort command
Posted By: MINER

Re: Delay in script execution - 11/21/18 10:52

Thank you again MatPed.....then im going to wait and capture the values on next trade.....or is there a way i can do this in the script?
Posted By: MatPed

Re: Delay in script execution - 11/21/18 11:05

use printf in the script. you need to capture it from the Zorro script and compare it with the value you see in MT4.
Posted By: MINER

Re: Delay in script execution - 11/21/18 11:10

Thank you MatPed....and how will i use that data to solve the problem of delayed entries/exits?
Posted By: Spirit

Re: Delay in script execution - 11/23/18 20:32

You can then see where and why it happens, and fix it.
© 2024 lite-C Forums