Gamestudio Links
Zorro Links
Newest Posts
Loging off automatically ?
by old_bill. 03/30/20 22:07
Need help to log in my broker into ZORRO
by buttcorgi. 03/30/20 19:52
textureLod into HLSL
by 3run. 03/30/20 18:01
Running banchmark test with FxPro on MT4
by Cobus. 03/30/20 14:55
Read Z12.fac while running Z2
by AndrewAMD. 03/29/20 22:32
Comment Out
by danatrader. 03/29/20 22:03
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
3 registered members (AndrewAMD, jbhunter, alibaba), 675 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
gonzalez21, Cobus, HF_Psy, jj02520024, heitorfr
18409 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
enum case / if else #479159
02/25/20 21:25
02/25/20 21:25
Joined: Mar 2019
Posts: 37
D
danatrader Offline OP
Newbie
danatrader  Offline OP
Newbie
D

Joined: Mar 2019
Posts: 37
Again, I am sorry for bothering, but for most of you easy question.


Following works fine in Lite-C:

Code
while(algo(loop("TRND"))) //,"ALGO2","ALGO3","ALGO4")))
		{
			NumComponents = NumLoops1*NumLoops2;
			algoSetup();
			equityCurve();
			switch(Algo) {
				case "TRND": tradeTRND(); break;
				//case "ALGO2": tradeCNTR(); break;
				//case "ALGO3": tradeALGO3(); break;
				//case "ALGO4": tradeALGO4(); break;
// add more algos here
			}


Cause of my lack of knowledge, changing the code I have to C / C++ (dll) I get some errors on compilation in the complete context.
Those I solved, but, the case / switch wants an enumeration.
Don't get it peroper to be accepted by the compiler.


So changed to "if else"

Code
if (0 == strcmp(Algo, "TRND"))
				tradeTRND();
			else if (0 == strcmp(Algo, "CNTR"))
				tradeCNTR();


compiles without errors, just doesn't seem to be correct...

Any advice?

Re: enum case / if else [Re: danatrader] #479160
02/25/20 21:31
02/25/20 21:31
Joined: Feb 2017
Posts: 895
Chicago
AndrewAMD Online
User
AndrewAMD  Online
User

Joined: Feb 2017
Posts: 895
Chicago
Your strcmp approach appears to be correct, so perhaps it's some other bug?

Re: enum case / if else [Re: danatrader] #479162
02/25/20 21:39
02/25/20 21:39
Joined: Mar 2019
Posts: 37
D
danatrader Offline OP
Newbie
danatrader  Offline OP
Newbie
D

Joined: Mar 2019
Posts: 37
Yes, somewhere something isn't structured properly I think.
But can't grab it frown


Code

#include "stdafx.h"
#include <zorro.h>
#include <Reflex.c>

/* Trading 4 user specified algorithms
for a portfolio of assets
in a separate asset list.
User control by Capital and Panic (profit lock) sliders.
Exit by reversal and trailing stop loss.
Equity curve (phantom) trading.
OptimalF capital allocation.
Reinvestment with square root rule.
WFO training.*/


// User definitions ////////////////////////////////

#define ASSETLIST		"AssetsCurTest"	
#define STARTDATE		2012	// backtest period
#define BARPERIOD		60	
#define LOOKBACKBARS	500
#define ATRPERIOD		30		// for stop distance
#define MAXCAPITAL	10000	// slider limit
#define CAPITALFACTOR 30	// adjust for slider capital ~ required capital
//#define ZERO_COST		// Test with no spread & commission
#define WFOCYCLES		10
#define MAXTRADES		2
#define RETRAINDAYS	100	// retraining period
#define PHANTOMTIME	20		// equity curve trading

/////////////////////////////////////////////////////
//Trading Algos

vars Prices;
var Atr, Panic;
int NumComponents = 1;

// example algo

void tradeTRND()
{
	var TimePeriod = optimize(0.1, 0.025, 0.5, 0.025, 0);
	vars SmoothPrice = series(Laguerre(Prices, TimePeriod));
	int FilterPeriod = optimize(300, 50, 500, 100, 0);

	vars MMI_Raws = series(MMI(Prices, 300));
	vars MMI_Avgs = series(SMA(MMI_Raws, 300));

	if (falling(MMI_Avgs)) {
		if (valley(SmoothPrice)) {
			exitShort(); enterLong();
		}
		else if (peak(SmoothPrice)) {
			exitLong(); enterShort();
		}
	}
}

void tradeCNTR()
{
	// calculate the buy/sell signal with optimized parameters
	vars PriceAvg = series(price(0));
	vars Filtereds = series(BandPass(PriceAvg, optimize(30, 20, 40, 3, 0), 0.5));
	vars Signals = series(FisherN(Filtereds, 500));
	var Threshold = optimize(1, 0.5, 1.5, 0.1, 0);

	// buy and sell
	Stop = optimize(4, 2, 10, 2, 0) * ATR(100);
	Trail = 4 * ATR(100);

	if (crossUnder(Signals, -Threshold))
		enterLong();
	else if (crossOver(Signals, Threshold))
		enterShort();
}


void algoSetup()
{
	MaxLong = MaxShort = MAXTRADES;
	// order comment
	brokerCommand(SET_COMMENT, (DWORD)Algo);
	// Reinvestment with square root rule. 
	var CapitalPerComponent = abs(Capital) / NumComponents;
	Margin = OptimalF * CapitalPerComponent * CAPITALFACTOR * sqrt(max(0.5, 1 + ProfitClosed / CapitalPerComponent));
	// Exit by reversal and trailing stop loss. 
	Hedge = 5;
	Stop = optimize(10, 4, 30, 2, 0) * Atr;
	Trail = Stop;
	TrailLock = Panic;
}

// Equity curve (phantom) trading
void equityCurve()
{
#ifdef PHANTOMTIME
	vars Equities = series(LowPass(series(ProfitClosed + ProfitOpen), 8));
	var EquitySmooth = LowPass(Equities, PHANTOMTIME);
	if (falling(Equities) && Equities[0] < EquitySmooth && LossStreakLong + LossStreakShort > 2) {
		setf(TradeMode, TR_PHANTOM);
	}
	else {
		resf(TradeMode, TR_PHANTOM);
	}
#endif
	return;
}

/////////////////////////////////////////////////////

DLLFUNC void run()
{
	set(LOGFILE, PLOTNOW);
	BarPeriod = BARPERIOD;	// 1 hour bars
	LookBack = LOOKBACKBARS;	// needed for Fisher()
	StartDate = STARTDATE;
	setf(PlotMode, PL_DIFF);

#ifdef WFOCYCLES	
	NumCores = 16;		// use multiple cores (Zorro S only)
	set(PARAMETERS, FACTORS);  // generate and use optimized parameters and factors
	NumWFOCycles = WFOCYCLES; // activate WFO
#endif

// User control by Capital and Panic (profit lock) sliders. 
	Capital = -slider(1, MAXCAPITAL / 4, 0, MAXCAPITAL, "Capital", "Invested capital");
	Panic = slider(2, 0, 0, 100, "Panic", "Profit lock %");
#ifdef ZERO_COST // for testing only
	Spread = Commission = Slippage = RollLong = RollShort = 0;
#endif

#ifdef RETRAINDAYS
	ReTrainDays = RETRAINDAYS;
	if (ReTrain) {
		UpdateDays = -1;	// update price data from the server 
		SelectWFO = -1;	// select the last cycle for re-optimization
		set(FACTORS | OFF);	// don't generate factors when re-training
	}
#endif

	// portfolio loop
	assetList(ASSETLIST);
	while (asset(loop(Assets)))
	{
		Prices = series(priceClose(0));
		Atr = ATR(ATRPERIOD);
		while (algo(loop("TRND", "CNTR"))) //"TRND",,"ALGO2","ALGO3","ALGO4")))
		{

			NumComponents = NumLoops1 * NumLoops2;
			algoSetup();
			equityCurve();

			
			if (0 == strcmp(Algo, "TRND"))
				tradeTRND();
			else if (0 == strcmp(Algo, "CNTR"))
				tradeCNTR();

				//case "AI": tradeAI(); break;
				//case "AI2": tradeAI2(); break;
// add more algos here
		
		}
	}
	if (Init) printf("\n%i components", NumComponents);
}




Last edited by danatrader; 02/25/20 21:44.
Re: enum case / if else [Re: AndrewAMD] #479163
02/25/20 21:54
02/25/20 21:54
Joined: Mar 2019
Posts: 37
D
danatrader Offline OP
Newbie
danatrader  Offline OP
Newbie
D

Joined: Mar 2019
Posts: 37
I am again thankful for your help, just may you check if you see something obvious?

Re: enum case / if else [Re: danatrader] #479180
02/27/20 00:07
02/27/20 00:07
Joined: Mar 2019
Posts: 37
D
danatrader Offline OP
Newbie
danatrader  Offline OP
Newbie
D

Joined: Mar 2019
Posts: 37
Actually the mistake is simple, difference Lite-C to C/C++ --> Do not ommit parameters, although there is one that does not get shown, cause by definition it would be correct.

Tiny but tricky laugh


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1