Hi, I LOVE AMIBROKER, well to be honest at the beggining I hated it, I was used to program in MQL5 ( coding logic was easier for me ), so I didn't even touched AB for a couple of years, until a few months ago I decided to give it a try, fell in love with it, I knew I could trade in IB with AB but seemed a bit scary ( complicated ) a few days ago I opened a real account with IB and slowly started to think about AB, so I managed to connect AB with IB with the plugin, then I was able to place my first order using amibroker, today I learned how to place stop loss and take profit ( I'm really excited about the posibilities ) now I have one problem when my entry condition is True, it sends multiple PlaceOrders requests making it dangerous, I tried to find a way to only place 1 trade at a time ( in each symbol ) but still everything I try doesn't work, I even tried this
preventing-repeat-orders-and-whipsaws
suggested by Tom in some other post, but I'm gonna be honest, I don't even know how to implement it in my code, its all chinese to me, so please anybody save me is there a way to only allow one trade at a time? )
I'm afraid to share my code coz I know theres gotta have 10000000000 mistakes ( I'm just learning ) any advice its welcome.
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("activar_Robot");
strategy1 = Param("strategy1",0,0,1,1,0);
Send_Orders = Param("Send_Orders",0,0,1,1,0);
Simbolo_full_name = ParamStr("SYMBOL-EXCHANGE-TYPE-CURRENCY","XPON-NASDAQ-STK-USD");
_SECTION_END();
SetPositionSize(1,spsShares);
if(strategy1)
{
Up_level = Max(HHV(Ref(C,-1),5),HHV(Ref(O,-1),5));
Down_level = Min(LLV(Ref(C,-1),5),LLV(Ref(O,-1),5));
Buy_signal = IIf(Ref(Volume,-1) > HHV(Ref(Volume,-2),5),L,Null) AND Ref(C > Up_level,-1);
take_profit_level = IIf(Buy_signal,O + Ref(Up_level - Down_level,-1),Null);
stop_loss_level = IIf(Buy_signal,Ref(Down_level,-1),Null);
Buy = IIf(take_profit_level > 0 ,True,False) ;
Sell = 0;
ApplyStop(stopTypeLoss,stopModePoint,Open - stop_loss_level,1,False,0,0,-1,0);
ApplyStop(stopTypeProfit,stopModePoint,take_profit_level - Open,1,False,0,0,-1,0);
ShareSize = 1; //round(200 / LastValue(Close));
if(Send_Orders)
{
if( LastValue( Buy ) )
{
ibc = GetTradingInterface("IB");
// check if we are connected OK
if( ibc.IsConnected() )
{
// Transmit order
parentID = ibc.PlaceOrder(Name(), "Buy", ShareSize, "MKT", 0, 0, "Day", False);
ibc.PlaceOrder(Name(), "SELL", ShareSize, "LMT", LastValue(take_profit_level), 0, "Day", False, 1, "", parentID);
ibc.PlaceOrder(Name(), "SELL", ShareSize, "STP", 0, LastValue(stop_loss_level), "Day", False, 1, "", parentID);
}
}
}
Plot(Up_level,"Up_level",colorgold,styleLine,Null,Null,0,1,2);
Plot(Down_level,"Down_level",colorBlue,styleLine,Null,Null,0,1,2);
PlotShapes(IIf(Buy_signal > 0,1,0),colorGreen,0,L,-12,0);
PlotShapes(IIf(Buy_signal > 0,21,0),colorGreen,0,take_profit_level,0,0);
PlotShapes(IIf(Buy_signal > 0,21,0),colorRed,0,stop_loss_level,0,0);
Plot(take_profit_level,"take_profit_level",colorWhite,styleNoDraw,Null,Null,0,0,1);
Plot(stop_loss_level,"stop_loss_level",colorWhite,styleNoDraw,Null,Null,0,0,1);
}