Size number,the amount of symbols in the portfolio will obviously not exceed it):double EQUITY[ ][100];//first dimension is for bar,while the second one is for symbols Price for all symbols as follows`for(int i=0;i<variables+constant;i++)//portfolio symbols loop(variable and model constant){int shift=iBatShift(SYMBOLS[i],Time frame,zero_time);//receive bar index by time for a zero point opening[i]=iClose(SYMBOLS[i],Time frame,shift);//receive the bar’s price and save it in the array}points=0;//calculate points in the variable dateTime current_time=zero_time;//start a loop from the zero point while(current_time<=limit_time)//pass a long the time labels in the optimization interval{bool skip_bar=false;for(int i=0;i<variables+constant;i++)//portfolio symbol loop(variable and model constants)if(iBarShift(SYMBOLS[i],Time frame,current_time,true)==-1)//check bar existence for the symbol skip_bar=true;//if the bar does not exist,skip it for other symbols if(!skip_bar)//continue operation if the bar is synchronized between all symbols{points++;//increase the number of points by one TIMES[points-1]=current_time;//store time label in memory for(int i=0;i<variables+constants;i++)//main profit calculation loop for all symbols in the point{int shift=iBarShift(SYMBOLS[i],Time frame,current_time);//receive the bar index by time closingi[i]=iClose(SYMBOLS[i],Time frame,shift);//receive the bar’s price double CV=ContractValue(SYMBOLS[i],currenrt_time,Time frame);//calculate the contract price profit[i]=(closing[i]-opening[i])*CV; EQUITY[points-1,i]=profit[i];//save the profit value}}current_time+=Time frame*60;//shift to the next time interval}
Leave a comment