Search for parameter that changes when new ticks arrive

Is there a parameter that changes with every bar being formed. I am trying to fire signals once per bar but not successful.

Depending on what data source you are using and whenever plugin supplies appropriate info you can get for example time of last update and remaining times using
http://www.amibroker.com/f?status
and
http://www.amibroker.com/f?getrtdata

Look for
"lastbarend" - returns DateTime of the end of last bar. For example 5 -minute bar at 9:00 will have end time of 9:04:59 (works for time-based bars only) (v5.60)
"lastbartimeleft" - returns number of seconds to the completion of current last bar. Works for time-based bars only. Note that for proper operation this requires database timeshift to be set properly (so dates displayed on chart match your local computer time zone). (v5.60)
"lastbartimeleftrt" - it works like "lastbartimeleft" but uses the most recent RT stream update time instead of Now(). Also added Status("lastrtupdate") - time of last RT stream update Depends on RT plugin to deliver correct DateUpdate / TimeUpdate data. If plugin or date source sends incorrect datetimestamps or does not send DateUpdate/TimeUpdate correctly this function will not operate properly. Note that most data sources send weird (not current) datetime stamps on weekends. Also IQFeed plugin sends DateUpdate/TimeUpdate only inside regular trading hours. (v5.60)
"lastrtupdate" - returns date time of last update sent by RT plugin (see remarks above) (v5.60)

Also really, use SEARCH https://forum.amibroker.com/search?q=completed%20bar because the answers are already there on the forum:

2 Likes

Moderator comment: Moved from duplicate thread

How to get one signal per bar in my code, as it is sending signals every second.

_SECTION_BEGIN("Point & Figure");
Version(4.40);

SetBarsRequired(100000,100000);

//Size for P&F boxes
boxsize=Param("Box Size",.5,0,100,0.5);
Box = LastValue(boxsize);
HX = round((H/box)*10)/10;
LX = round((L/box)*10)/10;
RH = floor(HX);
FL = ceil(LX);
///////////////////////////////////////////////////////////////////////
brd=Null;
if(IsNull(brd))
{
brd = CreateStaticObject("pibridge.Bridge");
}
if(!brd.GetConnectionStatus()) brd.Reconnect();
//////////////////////////////////////////////////////////////////////

// initialize first element
j = 0;

Reverse_ = Param ("Reverse",3,1,20,1);                      // reversal requirement

PFC[j] = FL[0];
PFO[j] = PFC[j] + 1;
down = 1;                  // By default the first bar is a down bar.
up = 0;
swap = 0;

// perform the loop that produces PF Chart
for( i = 1; i < BarCount; i++ )
{

 if( FL[i] <= PFC[j]-1 && down)         //continue down
 {
  PFC[j] = FL[i];
  PFO[j] = PFC[j] + 1;
 }
 else
 {
  if( RH[i] >= PFC[j] + Reverse_ && down)  //Change direction to up
  {
   j++;
   swap = 1;
   PFC[j] = RH[i];
   PFO[j] = PFC[j]-1;
  }
 }
 if( RH[i] >= PFC[j] + 1 && up)         //Continue up
 {
  PFC[j] = RH[i];
  PFO[j] = PFC[j] - 1;
 }
 else
 {
  if( FL[i] <= PFC[j] - Reverse_ && up)   //Change direction to down
  {
   j++;
   PFC[j] = FL[i];
   PFO[j] = PFC[j] + 1;
   swap = 1;
  }
 }
 if( swap )
 {
  swap = 0;
  if( up )
  {
   up = 0;
   down = 1;
  }
  else
  {
   up = 1;
   down = 0;
  }
 }
}
delta = BarCount - j-1;


PFO = Ref( PFO, -delta );
PFC = Ref( PFC, -delta );

// High-Low range sets the height of the P&F bar
H = IIf(Ref(PFC,-1)>Ref(PFO,-1),Ref(HHV(PFC,1),-1)-1,Max(PFO,PFC))*Box;
L = IIf(Ref(PFC,-1)<Ref(PFO,-1),Ref(LLV(PFC,1),-1)+1,Min(PFO,PFC))*Box;
O = IIf(Ref(PFC,-1)>Ref(PFO,-1),Ref(HHV(PFC,1),-1)-1,IIf(Ref(PFC,-1)<Ref(PFO,-1),Ref(LLV(PFC,1),-1)+1,PFO))*Box;

// the difference between Open AND Close should be set to box size
// the sign decides if X or O are plotted
C = O+ Box * IIf( PFC > PFO, 1,-1);

GraphXSpace = 2;
Title ="No Jscript  " + Name()+ "  PF HiLo, H: " + H+ ", L: " + L+", Box: "+ box + ", Reversal: " + Reverse_;

Plot( C, "P&F Chart Close", IIf( PFC > PFO, colorBlue, colorRed ), styleCandle+styleNoLabel+stylePointAndFigure);


//Calculating Minima
function Minimas(n){
Mins = 99999;
for(i=0;i<n;i++){
Mins = Min(Ref(L,-i),Mins);
}
return Mins;
}

//Calculating Maxima
function Maximas(n){
Maxs = -99999;
for(i=0;i<n;i++){
Maxs = Max(Ref(H,-i),Maxs);
}
return Maxs;
}

Plot(Minimas(10),"Minima",colorBlue,styleLine);
Plot(Maximas(10),"Maxima",colorOrange,styleLine);
/////////////////////////////////////////////////////////////////////////////////

Longs1 = (H > Ref(Maximas(10),-1)+boxsize*.999);
Shorts1= (L < Ref(Minimas(10),-1)-boxsize*.999);
Long_entry1 = Longs1;
Buy2 = Long_entry1;

Sell2 = Shorts1;

Buy2 = ExRem(Buy2,Sell2);
Sell2 = ExRem(Sell2,Buy2);

/////////////////////////////////////////////////////////////////////////////////
Longs = (H > Ref(Maximas(10),-1)+boxsize*.999);
Shorts= (L < Ref(Minimas(10),-1)-boxsize*.999);
Long_entry = Longs;
Buy1 = Long_entry;
Sell1 = Shorts;
Buy1 = ExRem(Buy1,Sell1);
Sell1 = ExRem(Sell1,Buy1);
Buy = Long_entry AND Buy2;
x = ValueWhen(Buy1,Ref(Maximas(10),-1));
Sell = Shorts;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
BuyL = LastValue(Buy);
SellL = LastValue(Sell);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (BuyL)
{
brd.PlaceOrder("NSE", "INFY-EQ", "NIFTY","MY-LongEntry", 1,1,1,0, 0, "MKT", "NRML", "ZK1110","DAY");

}
if (SellL)
{
brd.PlaceOrder("NSE", "INFY-EQ", "NIFTY","MY-LongExit", 2,1,1,0, 0, "MKT", "NRML", "ZK1110","DAY");

}

Short = 0;
Cover = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
shape = Buy*shapeUpArrow + Sell*shapeDownArrow;
PlotShapes(shape,IIf(Buy,colorGreen,colorRed),O,IIf(Buy,Low,High));PlotShapes( IIf( Sell , shapeHollowDownArrow,0) , colorRed ,layer = 0);
Plot(x,"value",colorRed,styleDots);
_SECTION_END();```

@Tomasz Please help me on the afl I've posted. Thanks!

I have given you plenty of material to work on your code already.
The articles already answer the question you had.

There are other articles like this: http://www.amibroker.org/userkb/2007/07/14/preventing-repeat-orders-and-whipsaws/
and this Preventing repeatition of trade in LiveAutoTrading

You need to fix your own code yourself. If you read the articles above you would know how. If you can't fix it yourself, you can hire programmer to do that for you Third party services, blogs, courses, books, add-ons

1 Like
RequestTimedRefresh( 1 ); 
ibc = GetTradingInterface("IB"); 
Transmit = ParamToggle("Transmit","OFF|ON",0); 
BuyTrigger = ParamTrigger("Place Buy order","BUY"); 
SellTrigger = ParamTrigger("Place Sell order","SELL"); 
Reset = ParamTrigger("Reset All","RESET"); 
PrevTN = StaticVarGet("TimeNumber"); 
TN = LastValue(TimeNum()); 
NewBar = TN != PrevTN; 
StaticVarSet("TimeNumber",TN); 
BuyOrderID = StaticVarGetText("BuyOrderID"); 
SellOrderID = StaticVarGetText("SellOrderID"); 
BuyPending = ibc.IsOrderPending(BuyOrderID); 
SellPending = ibc.IsOrderPending(SellOrderID); 
if( NewBar ) 
{ 
if( NOT BuyPending ) StaticVarSetText("BuyOrderID",""); 
if( NOT SellPending ) StaticVarSetText("SellOrderID",""); 
SetChartBkColor( colorWhite ); 
} 
if( BuyTrigger AND BuyOrderID == "" ) 
{ 
BuyOrderID= ibc.ModifyOrder( BuyOrderID, Name(), "Buy", 100, "MKT", 0, 0, "Day", Transmit); 
StaticVarSetText("BuyOrderID",BuyOrderID); 
SetChartBkColor( colorBrightGreen ) ; 
} 
else if( SellTrigger AND SellOrderID == "" ) 
{ 
SellORderID = ibc.ModifyOrder( SellORderID , Name(), "Sell", 100, "MKT", 0, 0, "Day", Transmit); 
StaticVarSetText("SellOrderID",SellOrderID); 
SetChartBkColor( colorRed ) ; 
} 
else if( Reset ) 
{ 
StaticVarSetText("BuyOrderID",""); 
if( BuyPending ) ibc.CancelOrder( BuyOrderID ); 
StaticVarSetText("SellOrderID",""); 
if( SellPending ) ibc.CancelOrder( SellOrderID ); 
ibc.CloseAllOpenPositions(); 
} 
LastTWSMsg = ibc.getLastError( 0 ); 
BuyStatus = WriteIf( BuyOrderID != "", BuyOrderID+", Status: "+ibc.GetStatus( BuyORderID, True ),""); 
SellStatus= WriteIf( SellOrderID != "", SellOrderID+", Status: "+ibc.GetStatus( SellORderID, True ),""); 
LastBuyTime= Nz(StaticVarGet("LastBuyTime")); 
LastSellTime= Nz(StaticVarGet("LastSellTime")); 
Title = "\n"+ 
"Last TWS Error Msg: "+LastTWSMsg+"\n"+ 
" BuyOrderID: "+BuyStatus+"\n"+ 
" SellOrderID: "+SellStatus+"\n"+ 
"TWS Position Size: "+NumToStr(ibc.GetPositionSize( Name() ),1.0,False); 
Plot(C,"Close",colorBlack,styleBar); [quote="Manoj.Dalmia, post:1, topic:6423, full:true"]
Is there a parameter that changes with every bar being formed. I am trying to fire signals once per bar but not successful.
[/quote]

Can someone explain me what the above code is doing. Like the ibc part, and ibc.modifyorder part

If you wrote the code yourself - you should know what it is doing.

If you did not write the code yourself:
a) you should have permission of author to publish it
b) you can contact author to explain what the code does

If b) is impossible you can hire somebody to help you: Third party services, blogs, courses, books, add-ons

It is the code given in the help link provided by you. Author is not shown there @Tomasz

If the code is taken from Knowledge Base, then the explanation what it is doing is included in the relevant article. If you don't know what given function is doing you should consult relevant part of documentation http://www.amibroker.com/at/

1 Like