|
Plot questions - multisymbol and trade placement
#467116
07/16/17 21:04
07/16/17 21:04
|
Joined: Jun 2017
Posts: 78
BobbyT
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2017
Posts: 78
|
Hi all, I have two questions. 1) Is it possible to place a mark on the plot for when a pending trade was placed? This mark would then be joined to when the trade was entered. Therefore 3 marks and 2 lines on the plot per trade. How would one go about this. 2) I am not getting the following block (from the manual) to operate on a multisymbol strategy.
char name[40]; // string of maximal 39 charactersstrcpy(name,Asset);
strcat(name,":");
strcat(name,Algo);
var equity = EquityShort+EquityLong;
if(equity != 0) plot(name,equity,NEW|AVG,BLUE);
At present, it only plots price, equity graph and equity line for the last symbol in the asset loop. Could someone please clarify how plot collects data so I can work out where this needs to be. Where should this block be implemented and what is the required program flow to allow said implementation. At present my code runs like so
run()
->Asset loop {
->LookForTrades() ->set up price/indicator series, check entry conditions, enter trades
... }
->plot code block as per above
run()
...
Cheers, BobbyT Edit: I would like to extend question 2 to multi-timeframe multi-symbol strategies. That is, I would like to plot a chart for each asset-timeframe combination
Last edited by BobbyT; 07/16/17 21:22.
|
|
|
Re: Plot questions - multisymbol and trade placement
[Re: jcl]
#467132
07/17/17 16:12
07/17/17 16:12
|
Joined: Jun 2017
Posts: 78
BobbyT
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2017
Posts: 78
|
Thanks JCL 1) From what I can gather from the manual, TradeBarOpen for pending trades is reset to the bar the trade was oped once it reaches TradeEntryLimit. Does this mean plotGraph() should be called immediately after (and before) TradeEntryLimit is hit. Or is there a better way? 2) I saw reference to the order of plot calls in the manual. But I was unable to make much sense of it. Taking the above question into consideration, would the best way to maintain the plot order call, would this be appropriate program structure.
run
{
while(asset(loop("AUD/USD","EUR/USD")))
while(algo(loop("M5","M15")))
if(algo == "M5")
{
Indicator/signal operations
...
ThisTrade = enterLong();
Generate plot compatible date with calls to year(),month() etc -> pendingDate
plot(signal, "signal", 0, RED);
plotGraph(pendingPrice, pendingDate, TradeEntryLimit, DOT, GREEN);
}
if(algo == "M15")
{
...
}
}//end run()
Cheers, BobbyT
|
|
|
Re: Plot questions - multisymbol and trade placement
[Re: BobbyT]
#467139
07/18/17 03:19
07/18/17 03:19
|
Joined: Jun 2017
Posts: 78
BobbyT
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2017
Posts: 78
|
Update: I have the following (pseudo) code which is now plotting the pending price of each trade as is it taken:
Pd = 0.0;
if(entryConditions)
{
Entry = some_price;
ThisTrade = enterLong();
Pd = Entry;
}
plot(signal, "signal", 0, RED);
if(Pd != 0.0) plotGraph("pd price", 0, Pd, CROSS, DARKGREEN);
I originally wanted to use ThisTrade as the control statement however it 'always' evaluates to true after the first trade is placed. If I'm thinking right, this is because ThisTrade stores the last taken trade, regardless of what bar it is on. Is there an 'official' way to control for the plotGraph() call so it only plots a symbol when a trade is placed. Also, I am no closer to joining the pending price and the opening price of individual trades. It obviously can be done as open/close prices are linked in the simulation charts but how...I have no idea. I don't see anything in the manual about it (other than LINE but I'm failing at implementing that) and I can't find any demo code demonstrating it Cheers, BobbyT PS Lets leave the 'plot per asset:algo' issue for another time. I figure it is likely best to get a function set familiarised before getting too funky EDIT: english
Last edited by BobbyT; 07/18/17 03:23.
|
|
|
Re: Plot questions - multisymbol and trade placement
[Re: jcl]
#467154
07/18/17 15:17
07/18/17 15:17
|
Joined: Jun 2017
Posts: 78
BobbyT
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2017
Posts: 78
|
Ok so I store the pending in one of my remaining TradeVar slots. Easy enough. As TradeVar are only available from loop(all_trades/open_trades) and TMF this points to 2 possibilities 1) All plot functions are called within a TMF which just doesn't sound right and you could end up with inconsistent series (out-of-sync plot calls) 2) Loop over open_trades and create a series of the pending bar to be passed back to plotGraph #2 seems to make more sense for how I understand zorro but seems (computationally) wasteful. There is no fixed delay between when trades are placed and when they are opened and I think this will cause issues for LINE. For example, say a pending trade (trade1) is placed @ bar1 but is not filled until bar20. Another trade (trade2) is placed at bar10 and is not filled until bar30. Won't LINE connect the pending bar of trade2 to the open bar of trade1 as it connects the 'last position to the current position'. I have to admit that besides pointers/memory functions, graphing functions are by far my weakest toolset. I really struggle with them in R. MQL4, not so bad. But I also haven't one anything to interesting on that front Cheers, BobbyT
|
|
|
Re: Plot questions - multisymbol and trade placement
[Re: BobbyT]
#467166
07/18/17 22:53
07/18/17 22:53
|
Joined: Jun 2017
Posts: 78
BobbyT
OP
Junior Member
|
OP
Junior Member
Joined: Jun 2017
Posts: 78
|
So I arrived at a solution. It's super ugly (code wise). I wrote a string of helper functions to get it working. It all of course is dependent on storing the pending bar in TradeVar as you previously indicated. The code is also dependant upon myID, a custom trade identifier as pending trades have no identifier until they are opened. Here's the helpers and the plot block (which is now called at the end of every bar, directly, in run():
//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
}
}
This code feels like it's taking the long way around. Is there a better way to do this such as official lite-c functions or just half-way decent programming? It does the job but seems very very crude Cheers, BobbyT PS: As this is 'working' now can I re-ask about asset:algo plots? I'd like to generate a separate plot for each asset:algo combination. I can see how the above functions could be adapted to do such a thing (I think) but from what I gather, Zorro, will only generate 1 plot per simulation. In multiasset strategies, new plots can be attained by selecting the asset in the Asset box and pressing results. I played with this and it works as the manual states. But this begs the question, how can one create a separate plot for each algo?
|
|
|
|