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".
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.
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",
473851, SB_DAY);
OpenPosition = TradeSize;
}
//===================================
TradeBar = BarCntr;
Strategy.doShort("SE",Strategy.LIMIT,Strategy.THISBAR,TradeSiz
e,entryprice);
drawLineRelative(-1,entryprice,1,entryprice, PS_SOLID, 2,
Color.red, "Sel"+BarCntr);
drawShapeRelative(0, high()+MakeGOffset(), Shape.DOWNARROW,
"", Color.red, Shape.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",
473851, SB_DAY);
OpenPosition = TradeSize;
}
//===================================
TradeBar = BarCntr;
Strategy.doLong("LE",Strategy.LIMIT,Strategy.THISBAR,TradeSiz
e,entryprice);
drawLineRelative(-1,entryprice,1,entryprice, PS_SOLID, 2,
Color.green, "Lng"+BarCntr);
drawShapeRelative(0, high()+MakeGOffset(), Shape.UPARROW,
"", Color.green, Shape.TOP | Shape.ONTOP , BarCntr+"Le");
stopprice=entryprice-StopLoss*getMinTick();
profittarget=entryprice+ProfitTarget*getMinTick();
}
}
Hope this helps further your goals. Good luck.
Comment