I have tried various techniques to maintain synchronization from multiple symbols from a higher time frame into a lower time frame without resorting to use of symbol spreads as I wish to perform various actions on each symbo, to then bring together into a unified indicator. As a simple example to highlight the issue, I have given the following code to just look at 2 symbols and find the MA of each and combining them into one indicator:-
Nothing I tried can make this work in terms of synchronization when putting an external interval into the study in a lower timeframe.
Any help/guidance will be much appreciated.
Robert
PHP Code:
// ###################################################################
// GLOBAL VARIABLES
// -------------------------------------------------------------------
// Used in preMain() for user selection
var aPArrG = new Array();
var xExample = null;
var myStudy1 = null;
var myStudy2 = null;
var bInit = false;
// ###################################################################
function preMain(){
// ###################################################################
// STUDY FIXED PARAMETERS
setPriceStudy(false);
setStudyTitle("MITst");
// VARIABLES
var k;
// USER SELECTION
k=0;
// Symbol & Interval
aPArrG[k] = new FunctionParameter( "sSymbol1P", FunctionParameter.STRING);
with( aPArrG[k] ) {
setDefault("$trin");
}
k++;
aPArrG[k] = new FunctionParameter( "sSymbol2P", FunctionParameter.STRING);
with( aPArrG[k] ) {
setDefault("$trinq");
}
k++;
aPArrG[k] = new FunctionParameter( "nIntervalP", FunctionParameter.STRING);
with( aPArrG[k] ) {
setDefault();
}
k++;
// ==================================================================
} // END PreMain Function
// ==================================================================
// ##################################################################
function main(sSymbol1P, sSymbol2P, nIntervalP) {
// ****************************************
if ( bInit == false ){
// ----------------------------------------
if(nIntervalP == null) nIntervalP = getInterval();
if(sSymbol1P == null) sSymbol1P = getSymbol();
vSymbol1M = sSymbol1P+","+nIntervalP;
if(sSymbol2P == null) sSymbol2P = getSymbol();
vSymbol2M = sSymbol2P+","+nIntervalP;
xExample = efsInternal("testExample", sSymbol1P, sSymbol2P, inv(nIntervalP));
bInit=true;
// ----------------------------------------
}
// ========================================
if (xExample != null) {
if (myStudy1 == null) myStudy1 = getSeries(xExample, 0 );
if (myStudy2 == null) myStudy2 = getSeries(xExample, 1 );
}
return -myStudy1-myStudy2;
}
function testExample(vSymbol1, vSymbol2) {
var MA1=ema(2, sym(vSymbol1) )
var MA2=ema(2, sym(vSymbol2) )
return new Array( MA1, MA2 );
}
Any help/guidance will be much appreciated.
Robert
Comment