Code not executed at the given interval

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #213065 quote
    sriramtgi
    Participant
    New

    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.

    1. The Code doesn’t get executed at every minute as expected
    2. I donot know why After 1,2 the ordersize goes to 8
    3. 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
    
    
    
    Capture1.jpg Capture1.jpg
    #213067 quote
    sriramtgi
    Participant
    New

    You can also see in this screenshot.. When the existing candle is moving same as previous candle, the code is not triggered at all

    Capture2.jpg Capture2.jpg
    #213085 quote
    Nicolas
    Keymaster
    Master

    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.

    KumoNoJuzza thanked this post
    #213086 quote
    sriramtgi
    Participant
    New

    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.

    #213107 quote
    GraHal
    Participant
    Master

    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
    #213108 quote
    GraHal
    Participant
    Master

    Unless I have missed something?

    Yes you have GraHal  … I just spotted the If Bearish / If Bullish Conditions higher up your code.

    #213109 quote
    sriramtgi
    Participant
    New

    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?

    #213111 quote
    GraHal
    Participant
    Master

    “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?

    #213112 quote
    GraHal
    Participant
    Master

    sometimes 1,2,8

    Have you investigated if the missing ‘4’ was an exit ordersize (as you use ordersize in your exits alsso)?

    #213156 quote
    sriramtgi
    Participant
    New

    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.

     

    1. The code must get triggered at every candle, but it doesn’t.
    #213159 quote
    GraHal
    Participant
    Master

    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

    sriramtgi thanked this post
    #213169 quote
    sriramtgi
    Participant
    New

    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..

    #213170 quote
    sriramtgi
    Participant
    New

    Also I was wondering there was no way to display a variable..

     

    I will try Graph command.. Thanks

    #213192 quote
    sriramtgi
    Participant
    New

    Tried Graph command, I get error “The instruction Graph is not allowed for automated trading”

    #213193 quote
    GraHal
    Participant
    Master

    GRAPH enables variables etc to be monitored during backtesting.

    Comment out GRAPH for AutoTrading //GRAPH.

    sriramtgi thanked this post
Viewing 15 posts - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.

Code not executed at the given interval


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
sriramtgi @sriramtgi Participant
Summary

This topic contains 15 replies,
has 3 voices, and was last updated by sriramtgi
2 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/10/2023
Status: Active
Attachments: 2 files
Logo Logo
Loading...