Hi all
i want to place order before 5 min candle close let say 4.58 Please help me how to do this
and how to use this lastbartimeleft in real programming
appricated you help
Hi all
i want to place order before 5 min candle close let say 4.58 Please help me how to do this
and how to use this lastbartimeleft in real programming
appricated you help
Hi All
below is my code to buy and sell at before candle close
i aim to buy or sell before candle close at 2 sec before ,
running the chat at 1m time
this code sowing buy or sell signal in amibroker but not sening signal to IB
please help me to correct this code
and to generate the lof file
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, High %g, Low %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
SetTradeDelays(0,0,0,0);
RequestTimedRefresh( 1 );
SetBarsRequired(200,0);
SetOption("AllowSameBarExit", True );
SetOption("HoldMinBars", 1 );
SetOption("SeparateLongShortRank", True );
PointValue = 20;
RoundLotSize = 1;
TickSize = 0.2;
TradeDelay = 0;
Buy = 1;
Sell = 1;
GraphXSpace = 5;
PositionSize = MarginDeposit = 1;
_SECTION_BEGIN("Signal Panel");
exitlong = Cross(s5d, H);
PlotShapes(exitlong * shapeNone, colorBlack,0,H,-10);
exitshort = Cross(L, s5d);
PlotShapes(exitshort * shapeNone, colorBlack,0,L,-15);
Buy = exitshort;
Sell = exitlong;
//Plot(s5d,"",colorRed,1);
//Plot(Ref(s5d,-1),"",colorYellow,1);
Plot(Ref(s5d,-1),"s5d",styleThick,styleLine);
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
AlertIf( Buy, "", "Buy @ " + C, 1 );
AlertIf( Sell, "", "Sell @ " + C, 2 );
for(i=BarCount-1;i>1;i--)
{
if(Buy[i] == 1)
{
entry = C[i];
sig = "Buy";
sl = s5d[i];
bars = i;
i = 0;
}
if(Sell[i] == 1)
{
sig = "Sell";
entry = C[i];
sl = s5d[i];
bars = i;
i = 0;
}
}
Offset = 20;
_SECTION_BEGIN(" Buy Sell Signal Confirm ");
BarColors =
IIf(BarsSince(Buy) < BarsSince(Sell)
AND BarsSince(Buy)!=0, colorGreen,
IIf(BarsSince(Sell) < BarsSince(Buy)
AND BarsSince(Sell)!=0, colorRed, colorBlue));
Plot(O, "Open", BarColors, styleNoTitle | ParamStyle("Style") | GetPriceStyle() ) ;
_SECTION_END();
_SECTION_BEGIN("Show Up Down Arrow & Price ");
shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
AlertIf( Buy, "SOUND C:\\Windows\\Media\\Chord.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );
Buy=Cover=Cross(C, s5d);
Sell=Short=Cross(s5d, C);
ShortPrice=SellPrice=Ref(s5d,-1);
CoverPrice =BuyPrice=Ref(s5d,-1);
_SECTION_BEGIN("Time Left");
sound = ParamToggle("Sound Alert", "ON | OFF");
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
if(sound)
{
Say( "New period" );
}
}
PlotTextSetFont(NumToStr(SecsToGo,1,False)+ " Sec Left", "Arial", 10, BarCount-1, Close[BarCount-1], colorred, colorDefault, -30 );
_SECTION_END();
ibc = GetTradingInterface("IB");
//if( ibc.IsConnected() ) // check if connection to IB was successfull
if (SecsLeft == 2 ) {
if( LastValue( Buy) )
{
ibc = GetTradingInterface("IB");
// if (buyLimit != null)
// buyLimit.Cancel();
if( ibc.IsConnected() )
{
if( ibc.GetPositionSize( Name() ) <= 0 AND NOT StrFind(ibc.GetPendingList( 1, "" ), Name()) )
{
ibc.PlaceOrder("NQU0-GLOBEX-FUT","BUY", 1,"MKT",LastValue(C) , 0, "Day", true );
}
}
}
//NQM9-GLOBEX-FUTt
//GTD YYYYMMDD HH:MM:SS TZONE
if( LastValue( Sell ) )
{
ibc = GetTradingInterface("IB");
if( ibc.IsConnected() )
{
if( ibc.GetPositionSize( Name() ) >= 0 AND NOT StrFind(ibc.GetPendingList( 1, "" ), Name()) )
{
ibc.PlaceOrder("NQU0-GLOBEX-FUT","Sell", 1,"MKT",LastValue(C) , 0, "Day", true );
}
}
}
if( LastValue( Cover ) )
{
ibc = GetTradingInterface("IB");
// if (buyLimit != null)
// buyLimit.Cancel();
if( ibc.IsConnected() )
{
if( ibc.GetPositionSize( Name() ) <= 0 AND NOT StrFind(ibc.GetPendingList( 1, "" ), Name()))
{
ibc.PlaceOrder("NQU0-GLOBEX-FUT","BUY", 1,"MKT",LastValue(C) , 0, "Day", true );
}
}
}
//NQM9-GLOBEX-FUT
if( LastValue( Short) )
{
ibc = GetTradingInterface("IB");
if( ibc.IsConnected() )
{
if( ibc.GetPositionSize( Name() ) >= 0 AND NOT StrFind(ibc.GetPendingList( 1, "" ), Name()) )
{
ibc.PlaceOrder("NQU0-GLOBEX-FUT","Sell", 1,"MKT",LastValue(C) , 0, "Day", true );
}
}
}
}
_SECTION_END();
Moderator comment: Read the forum rules and always use CODE TAGS. I added code tags for you this time but next time if you post without code tags, post will not be approved
Thanks a lot ,i am very new to this forum .Please tell me how to add code tag
Regards
Goyal
The second sub-heading at this link: