Great, thank you a lot, I call it from inside the trend.
Passing everything as argument.

Step by step, getting there.
Looks actually a lot nicer.


Okay, now that brings another problem.

I have a nice function to train the curves, I can also look at them in TEST.
But things change, once I try to add the real trading rules.

Either they are included in the train run, or in test, they are not shown.
Below full script so far.


Code

#include <default.c>
#include <Reflex.c>

function traincycles(vars Prices, int Cycle, int CycleFast, vars Signals, vars SignalsFast)
		{

			if(SignalsFast[0] > 0 && Signals[0] > 0) enterShort();
			if(SignalsFast[0] < 0 && Signals[0] < 0) enterLong();

		}

function tradeTrend()
{
	
	vars Prices = series(priceClose());
	
	int Cycle = optimize(10, 1, 55, 1);
	int CycleFast = optimize(1, 1, Cycle, 1);
	
	
	vars Signals = series(ReFlex(Prices,Cycle));
	vars SignalsFast = series(ReFlex(Prices,CycleFast));
	
	
	if(Train && !Test){
		traincycles(Prices, Cycle, CycleFast, Signals, SignalsFast);
	}

	int TrendCycle = Cycle + CycleFast;
	vars SignalsTrend = series(TrendFlex(Prices,TrendCycle));
	
	plot("ReFlex",Signals,NEW|LINE,RED);
	plot("ReFlexFast",SignalsFast,LINE,GREEN);
	plot("TrendFlex",SignalsTrend,LINE,YELLOW);

}

function run()
{
  if (is(INITRUN)) NumCores = 16;
  set(PARAMETERS+FACTORS+LOGFILE);
  BarPeriod = 1440; 
  LookBack = 2000;
  StartDate = 2005;
  NumTrainCycles = 3;
  //NumWFOCycles = 10;  
  Capital = 10000;
  MaxLong = MaxShort = 1;
  Hedge=5;

  if(ReTrain) {
    UpdateDays = -1;  
    SelectWFO = -1;	
    reset(FACTORS); 
  }
 
// double portfolio loop
  while(asset(loop("EUR/USD")))
  while(algo(loop("TRND")))
  {
    Margin = 0.5 * OptimalF * Capital;
    if(Algo == "TRND") 
      tradeTrend();
  }
}





Now I want to start adding simple "real rules" in the TREND Algo.
They should not be part of Train, but be part of Test, while the call off the traincycles function should be called always in test, but only in train on demand (e.g. edit script).

Code
	if(valley(SignalsTrend))
		enterLong();
	if(peak(SignalsTrend))
		enterShort();


Last edited by danatrader; 02/02/20 18:56.