Firstly my appreciation for this Prorealtime software. I am not a programmer, but I was able to learn and code so easily. Amazing stuff.
I wrote a code. The idea is to attach to 1 minute candle, so it execute at every minute. But the code is not getting executed at every minute, but at different interval. Sometimes I could not understand the logic when it gets triggered. What am I doing wrong. This is the simplest martingale code checking the previous candle . There are infact 3 issues. Please help me. Kindest regards.
- The Code doesn’t get executed at every minute as expected
- I donot know why After 1,2 the ordersize goes to 8
- The Code checking the CurrentMinute doesn’t work. I thought I will buy at 1 minute and sell at 59th minute.
ONCE OrderSize = 1
//IF CurrentMinute = 59 THEN
//ENDIF
//IF CurrentMinute = 1 THEN
isBullish = 0
isBearish = 0
IF Close[0] >= Open[0] THEN
isBullish = 1
ENDIF
IF Close[0] < Open[0] THEN
isBearish = 1
ENDIF
IF isBullish = 1 THEN
IF PositionPerf(0) < 0 THEN
OrderSize = OrderSize*2
ELSIF PositionPerf(0) >= 0 THEN
OrderSize = 1
ENDIF
IF LongOnMarket THEN
SELL OrderSize LOTS AT MARKET
ENDIF
IF ShortOnMarket THEN
BUY OrderSize LOTS AT MARKET
ENDIF
BUY OrderSize CONTRACTS AT MARKET
ENDIF
IF isBearish = 1 THEN
IF PositionPerf(0) < 0 THEN
OrderSize = OrderSize*2
ELSIF PositionPerf(0) >= 0 THEN
OrderSize = 1
ENDIF
IF LongOnMarket THEN
SELL OrderSize LOTS AT MARKET
ENDIF
IF ShortOnMarket THEN
BUY OrderSize LOTS AT MARKET
ENDIF
SELLSHORT OrderSize CONTRACTS AT MARKET
ENDIF
You can also see in this screenshot.. When the existing candle is moving same as previous candle, the code is not triggered at all
Code is read one time at candlestick Close and order is launch at next open. So a visual decay is observed and you might get lost on this.
Also, to open a SHORT position, use SELLSHORT instruction. SELL keyword is to close a long (BUY) position.
Dear Nucolas,
Thanks for the response.
Even in that case, the execution should be at the end of every candlestick. How come it misses out on many candles. Also apart from non execution, the lotsize also is different and not martingale as coded.
I have used SELLSHORT when I donot find any long position. Refer the last sell line.
All the Orders below will just trade at the start of each new bar as there are no conditions attached to the Orders so they always be True so they will always Trade?
Unless I have missed something?
IF LongOnMarket THEN
SELL OrderSize LOTS AT MARKET
ENDIF
IF ShortOnMarket THEN
BUY OrderSize LOTS AT MARKET
ENDIF
SELLSHORT OrderSize CONTRACTS AT MARKET
ENDIF
Unless I have missed something?
Yes you have GraHal … I just spotted the If Bearish / If Bullish Conditions higher up your code.
Yes Grahal, I have a bullish or bearish check.
But as per Nicolas, the code will be executed at the end of the candle stick. My problem is that the execution doesn’t happen for every candle as shown in the attachment. The lotsizes doesn’t increase as double, but 1,4 and sometimes 1,2,8.Moreover the syntax “CurrentMinute” variable doesn’t work.
Do you see the reason?
“CurrentMinute” variable doesn’t work.
The code in your OP, shows both references to CurrentMinute as // commented out, but I guess you know that?
So If CurrentMinute = 1 (end of bar) then Orders would be executed in CurrentMinute = 2 (at open of next bar) … are you taking this into account?
sometimes 1,2,8
Have you investigated if the missing ‘4’ was an exit ordersize (as you use ordersize in your exits alsso)?
I commented because it didn’t work. I gave for 59th minute and 1st minute.
There was no 4 in exit or entry, it just jumped to 8 or sometimes 16. I think it all had to do with the non execution of this code at every minute which is a basic problem.
- The code must get triggered at every candle, but it doesn’t.
From Line 22 to Line 29 at every bar you check if Long then Sell, If Short then Buy … there seems not much chance for any trade to accumulate profit?
What Timefame does the System run on?
Have you tried using below, at the bottom of your Code, so you can easily see when trades are triggered …
GRAPH LongTriggered
GRAPH ShortTriggered
The idea is to trade at 1st second and close at the 59th second.
Trade depends on previous candle bring bullish or bearish.
1) the code must get triggered every minute which is not happening
2) the martingale logic not working.. Donot know why as it seems right. This also could be tagged to previous one
3) CurrentMinute didn’t work so commented out
The code 22 to 27, I had vide this way because current minute is not working and I had to close any open position before I buy or sell for this current candle
Thanks for your help and guidance.
I have little experience in coding..
Also I was wondering there was no way to display a variable..
I will try Graph command.. Thanks
Tried Graph command, I get error “The instruction Graph is not allowed for automated trading”
GRAPH enables variables etc to be monitored during backtesting.
Comment out GRAPH for AutoTrading //GRAPH.