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 rdtdale, Today, 01:02 PM
    0 responses
    3 views
    0 likes
    Last Post rdtdale
    by rdtdale
     
    Started by alifarahani, Today, 09:40 AM
    3 responses
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by RookieTrader, Today, 09:37 AM
    4 responses
    18 views
    0 likes
    Last Post RookieTrader  
    Started by PaulMohn, Today, 12:36 PM
    0 responses
    7 views
    0 likes
    Last Post PaulMohn  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    41 views
    0 likes
    Last Post love2code2trade  
    Working...
    X