Messtone LLC

MetaTrader 4/Examples Portfolio trading in MetaTrader 4 A portfolio can be represented by the following equation:A*k1+B*k2+C*k3+…=F,where A,B,C…are time series corresponding to portfolio symbols k1,k2,k3…are symbol lots(positive-buy,negative-sell)F-target function(set by values in time series points)Sample function calculating the contract price as follows`double ContractValue(string symbol,datetime time,int period){double value=MarketInfo(symbol,MODE_LOTSIZE);string quote=SymbolInfoString(symbol,SYMBOL_CURRENCY_PROFIT);if(quote!=”USD”){string direct=FX prefix+quote+”USD”+FX_post fix;if(MarketInfo(direct,MODE_POINT)!=0){int shift=iBarShift(direct,period,time); double price=iClose(direct,period,shift);if(price>0)value*=price;}else{string indirect=FX_prefix+”USD”+quote+FX_post fix;int shift=iBarShift(indirect,period,time);double price=iClose(direct,period,shift);if(price>0)value/=price;}else{string indirect=FX_prefix+”USD”+Chart_Currency+FX_post fix;//from a reverse quote for the target currency int shift=iBarShift(indirect,period,time);double price=iClose(indirect,period,shift);if(price>0)value*=price;}}return(value);}

Leave a comment