Announcement

Collapse
No announcement yet.

PaperTrader

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

  • #16
    OK. Here's some somewhat advanced stuff.

    Let's say you are using the paper trader and you want to test, in realtime, the actions of your system by trying to better simulate trading actions with LIVE TRADING...

    You would want to include special conditions that setup each trade for BT and Paper Trading.

    So, for example, if I wanted to simulate a limit or stop order at a certain price, I would include something like the following to verify "I think I would get filled on this order".

    PHP Code:
            if ((takeshort) && (!Strategy.isShort()) ) {
                
    entryprice=low(-2); //-getMinTick(1);
                
    if ( ((getCurrentBarIndex() < 0) && (high() >= entryprice) &&
    (
    low() <= entryprice)) ||
                     ((
    getCurrentBarIndex() == 0) && (high() >= entryprice) &&
    (
    low() <= entryprice) && (close() >= entryprice+getMinTick(1)))
                ) {
                if ((
    getCurrentBarIndex() == 0) && (AutoTrade)) {
      
    debugPrintln"Trying to Enter SHORT @ :"+entryprice+" "+getMinTick()+"
    "
    +OpenPosition);
                 if ((
    Strategy.isLong()) && (OpenPosition 0)) {
    closePosition(getSymbol());  }
                  
    sellShortMarket(getSymbol(), TradeSize"Account Manager",
    473851SB_DAY);
                  
    OpenPosition TradeSize;
                }
                    
    //===================================
                    
    TradeBar BarCntr;
                  
    Strategy.doShort("SE",Strategy.LIMIT,Strategy.THISBAR,TradeSiz
    e
    ,entryprice);
                  
    drawLineRelative(-1,entryprice,1,entrypricePS_SOLID2,
    Color.red"Sel"+BarCntr);
                  
    drawShapeRelative(0high()+MakeGOffset(), Shape.DOWNARROW,
    ""Color.redShape.TOP Shape.ONTOP BarCntr+"Se");

                
    stopprice=entryprice+StopLoss*getMinTick();
                
    profittarget=entryprice-ProfitTarget*getMinTick();

                }
            }


            if ((
    takelong) && (!Strategy.isLong()) ) {
                
    entryprice=low(-1)-getMinTick();
                if ( ((
    getCurrentBarIndex() < 0) && (high() >= entryprice) &&
    (
    low() <= entryprice)) ||
                     ((
    getCurrentBarIndex() == 0) && (high() >= entryprice) &&
    (
    low() <= entryprice) && (close() <= entryprice-getMinTick()))
                ) {
                if ((
    getCurrentBarIndex() == 0) && (AutoTrade)) {
      
    debugPrintln"Trying to Enter LONG@ :"+entryprice+" "+getMinTick()+"
    "
    +OpenPosition);
                 if ((
    Strategy.isShort()) && (OpenPosition 0)) {
    closePosition(getSymbol());  }
                  
    buyMarket(getSymbol(), TradeSize"Account Manager",
    473851SB_DAY);
                  
    OpenPosition TradeSize;
                }
                    
    //===================================
                    
    TradeBar BarCntr;
                  
    Strategy.doLong("LE",Strategy.LIMIT,Strategy.THISBAR,TradeSiz
    e
    ,entryprice);
                  
    drawLineRelative(-1,entryprice,1,entrypricePS_SOLID2,
    Color.green"Lng"+BarCntr);
                  
    drawShapeRelative(0high()+MakeGOffset(), Shape.UPARROW,
    ""Color.greenShape.TOP Shape.ONTOP BarCntr+"Le");

                
    stopprice=entryprice-StopLoss*getMinTick();
                
    profittarget=entryprice+ProfitTarget*getMinTick();
                }
            } 
    Notice that I'm using two conditions to trigger these entries, the <0 and 0 return values of getCurrentBarIndex(). This is how you control BT vs. RT actions.

    Hope this helps further your goals. Good luck.
    Last edited by Doji3333; 10-23-2009, 06:23 PM.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #17
      Papertrade

      Doji
      You did so well on the last one, how about this? Each time I start, load, reload or even go to another page and come back to the page where my papertrade program is loaded on a chart it places an order without waiting for the conditions in the expression to be met. Everything I tried to stop this stopped the entire program from running. Seems like I need something to intialize and be ready without blindly placing an order.????

      Comment

      Working...
      X