Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem while realtime trading Dynamic contracts based on Account size

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Problem while realtime trading Dynamic contracts based on Account size

    I have a script which calculates realtime the slimit - number of contracts for /ES . All things look fine in the backtest simulation .

    But something strange happens in realtime

    slimit = (account_value + unrealized_profit)/800;

    if ( some condition )
    EnterLong(slimit);

    if (some condition)
    EnterShort(slimit)


    (10 min chart)
    Lets say I have $5000 is account it calculates and sold 6 contracts and then I take a loss of $1500 and my contracts (slimit) goes down to 4 , Condition switches from SHORT to LONG on the next bar.
    On execution I show this realtime: ( got this from Onexecution() )


    On execution of EnterLong(slimit) which is 4 now , and was short earlier with 6 contracts
    6 CONTACTS CLOSE POSITON
    6 CONTRACTS BUY TO COVER
    4 CONTACTS BUY

    in the end I have 10 contracts on buy side , which is wrong I should have 4 contracts on buy side.


    but It shows correctly like this in simulation.
    6 CONTRACTS BUY TO COVER
    4 CONTACTS BUY
    in the end 4 contracts buy side which is correct-----

    so my question is why and how to avoid this , so while I switch I always get on the buy side with correct number of contracts .

    I have dynamic script which keeps on adding and reducing contracts based on account value , all works well except this.
    Attached Files
    Last edited by hello_all; 05-09-2015, 10:03 AM.

    #2
    problem solved . there were 2 conditions coming in code
    entershort(slimit);
    exitlong();


    EOM

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, Yesterday, 11:51 AM
    0 responses
    16 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, Yesterday, 11:48 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-25-2026, 09:53 PM
    0 responses
    16 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 03-25-2026, 09:51 PM
    0 responses
    13 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 03-23-2026, 11:13 AM
    0 responses
    20 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X