Posted By: MatPed
Hint needed - 06/03/17 17:09
Hi I have found this strategy in the manual and I wanted to code it as an Algo to be traded in a multi-algo strategies, but I am facing several issue in doing that, I guess because I can not move an Asset loop in a function outside the Run().
Any Hint?
Thank you in advance
Any Hint?
Thank you in advance
Code:
// Currency Strength Strategy ///////////////////// // Exploits price shocks f.i. by CHF cap and Brexit function run() { BarPeriod = 60; ccyReset(); // reset strengths at begin of any bar Margin= 30; string Name; while(Name = (loop(Assets))) { if(assetType(Name) != FOREX) continue; // Currency pairs only asset(Name); vars Prices = series(priceClose()); ccySet(ROC(Prices,1)); // store price change as strength } // get currency pairs with highest and lowest strength difference string Best = ccyMax(), Worst = ccyMin(); var Threshold = 1.0; static char OldBest[8], OldWorst[8]; // static for keeping contents between runs if(*OldBest && !strstr(Best,OldBest)) { // new strongest asset? asset(OldBest); exitLong(); if(ccyStrength(Best) > Threshold) { asset(Best); enterLong(); } } if(*OldWorst && !strstr(Worst,OldWorst)) { // new weakest asset? asset(OldWorst); exitShort(); if(ccyStrength(Worst) < -Threshold) { asset(Worst); enterShort(); } } // store previous strongest and weakest asset names strcpy(OldBest,Best); strcpy(OldWorst,Worst); }