//check if a trade with status typ
bool tradesThisBar(string typ, int idx)
{
int n = 0;
for(all_trades){
if(strstr(typ, "Op")) { //looking at open trades
if(TradeBarOpen == idx) n++;
}
if(strstr(typ, "Cl")) { //looking at closed trades
if(TradeBarClose == idx) n++;
}
if(strstr(typ, "Pd")) { //looking at pendings only
if(PdBar == idx) n++;
}
}
if(n >= 1) return true;
else return false;
}
//get the bar index of a trade with status typ and myID id
int getTradeBar(string typ, int id)
{
int n = -1;
for(all_trades){
if(strstr(typ, "Op")) { //looking at open trades
if(id == myID) n = TradeBarOpen;
}
if(strstr(typ, "Cl")) { //looking at closed trades
if(id == myID) n = TradeBarClose;
}
if(strstr(typ, "Pd")) { //looking at pendings only
if(id == myID) n = PdBar;
}
}
if(n >= 0) return n;
else return -1;
}
//get myID for a trade with activity typ at bar idx
var getTradeMyID(string typ, int idx)
{
int n = -1;
for(all_trades){
if(strstr(typ, "Op")) { //looking at open trades
if(TradeBarOpen == idx) n = myID;
}
if(strstr(typ, "Cl")) { //looking at closed trades
if(TradeBarClose == idx) n = myID;
}
if(strstr(typ, "Pd")) { //looking at pendings only
if(PdBar == idx) n = myID;
}
}
if(n >= 1) return n;
else return -1;
}
//get price typ for trade with myID id
var getTradePrice(string typ, int id) //generalised version of getPendingPrice
{
var n = -1.0;
for(all_trades){
if(strstr(typ, "Op")) { //looking at open trades
if(id == myID) n = TradePriceOpen;
}
if(strstr(typ, "Cl")) { //looking at closed trades
if(id == myID) n = TradePriceClose;
}
if(strstr(typ, "Pd")) { //looking at pendings only
if(id == myID) n = TradeEntryLimit;
}
}
if(n >= 0) return n;
else return -1;
}
function run()
{
...
//mark where pending trades were placed
if(tradesThisBar("Pd", Bar)){
int id = (int)getTradeMyID("Pd", Bar);
plotGraph("pdbar", 0, getTradePrice("Pd", id), CROSS, CYAN);
}
//join the pending price/bar to the open price/bar
if(tradesThisBar("Op", Bar)){
int id = (int)getTradeMyID("Op", Bar);
if(id <= 0) return; //leave the function if no trade id was found
//sanity check >> are values being retrieved properly
//printf("nTrade: %i, PendingBarPrice: %i/%.5f, OpenBarPrice: %i/%.5f", id, getTradeBar("Pd", id), getTradePrice("Pd", id), Bar, getTradePrice("Op", id));
plotGraph("pdline", -(getTradeBar("Pd", id)-Bar), getTradePrice("Pd", id), LINE, CYAN); //pending point
plotGraph("pdline", 0, getTradePrice("Op", id), LINE|END, CYAN); //open point
}
}