Gamestudio Links
Zorro Links
Newest Posts
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Trading Journey
by 7th_zorro. 04/27/24 04:42
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (TipmyPip, Ayumi), 773 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
DeepLearn, introduce new feature #488027
12/31/23 04:39
12/31/23 04:39
Joined: Mar 2021
Posts: 35
Ocean county, Florida
NewtraderX Offline OP
Newbie
NewtraderX  Offline OP
Newbie

Joined: Mar 2021
Posts: 35
Ocean county, Florida
Hello,
How do I add a new parameter to AdviseLong function

Below code, I wanted to add the Close[0] as a parameter to the adviseLong Funtion, however didn't work.
I normalize it also.

.........................

vars Open = series(priceOpen());
vars High = series(priceHigh());
vars Low = series(priceLow());
vars Close = series(priceClose());
vars Price = series(price());
ColorUp = BLUE;
ColorDn = MAGENTA;


#ifdef DO_SIGNALS
SelectWFO = -1; // use the last WFO cycle for calibrating the neural net
if((vLong = adviseLong(SIGNALS+BALANCED,0,
#else
set(LOGFILE|PLOTNOW);
if((vLong = adviseLong(NEURAL+BALANCED,0,
#endif
change(1),change(2),change(3),change(4),
range(1),range(2),range(3),range(4),Close[0]/100))> Threshold)
enterLong();
#ifndef DO_SIGNALS
if((vShort = adviseShort()) > Threshold)
enterShort();
#endif
plot("Long",vLong,NEW|LINE,BLACK);
plot("Short",vShort,LINE,GREY);
}

Attached Files
adviseLong.png (113 downloads)
adviseLong2.png (111 downloads)
Last edited by NewtraderX; 12/31/23 04:41.
Re: DeepLearn, introduce new feature [Re: NewtraderX] #488028
12/31/23 06:54
12/31/23 06:54
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
Please tell us what you know about built-in functions and user-defined functions. So we can help you more efficiently.

The reason is because the two have their limitations and advantages. But Disadvantages are always flexible enough to change into advantages. Thank you.


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: DeepLearn, introduce new feature [Re: TipmyPip] #488029
12/31/23 20:09
12/31/23 20:09
Joined: Mar 2021
Posts: 35
Ocean county, Florida
NewtraderX Offline OP
Newbie
NewtraderX  Offline OP
Newbie

Joined: Mar 2021
Posts: 35
Ocean county, Florida

var change(int n)
{
return scale((priceClose(0) - priceClose(n))/priceClose(0),100)/100;
}

var range(int n)
{
return scale((HH(n) - LL(n))/priceClose(0),100)/100;
}

above are the user defined function, these two came with the NN sample of Zorro manual, you can find the whole thing on zorro.

and that Close on line 110 is defined on line 74 of the first image.


to reiterate original question:
How Do I add additional parameters to adviseLong or adviseShort function?

Re: DeepLearn, introduce new feature [Re: NewtraderX] #488031
01/01/24 09:23
01/01/24 09:23
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
Thank you for your response, The reason I asked you the question because I suppose you already know what are the definitions of user-defined functions, and built-in functions,

You gave me examples of user-defined functions, but not the definition of what is user-defined functions, and the difference between built-in Functions.

But let's suppose you know the difference in the definition, If you know what output you are expecting from the built-in function, and you can create a user-defined function with the built-in function, this is a partial solution to your problem.
I know we are all here to improve on our mathematical programming abilities to improve our sophistication, but there are many solutions to your problems, some of them are very easy, with a lack of efficiency and accuracy, and others are much more
sophisticated, and at a higher level of accuracy relative to what kind of output solutions you expect to be satisfied with.

You can create a custom function that accepts any number of parameters inputs those parameters with a loop into the adviseLONG or SHORT, and then uses the output to input once again into the built-in functions, this is the easy solution.
But the solution has somewhat a lack of accuracy, compared to a Custom Neural Network that will accept a larger number of parameters.

Last edited by TipmyPip; 01/01/24 12:03.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: DeepLearn, introduce new feature [Re: TipmyPip] #488032
01/01/24 17:25
01/01/24 17:25
Joined: Mar 2021
Posts: 35
Ocean county, Florida
NewtraderX Offline OP
Newbie
NewtraderX  Offline OP
Newbie

Joined: Mar 2021
Posts: 35
Ocean county, Florida
Hey TipMyPip, What kinda post is this?

Are you trolling us in this forum?

Last edited by NewtraderX; 01/01/24 17:25.
Re: DeepLearn, introduce new feature [Re: NewtraderX] #488033
01/01/24 22:18
01/01/24 22:18
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
I am sorry you got the wrong impression, that was not my intention.

I gave you an answer that is a general solution, my approach to computer science, and programming is focused on giving a general answer, that would be suitable to any problem.
and it is for you to make sense of it, according to your mindset, and ideas.

And I love thinking for myself and finding out solutions as my abilities improve.

If you want an easy solution without developing ideas by yourself, it would be hard for me to know what kind of approach you prefer, the easy one, without a high level of accuracy, or the more complex one, which is a custom-defined Neural Network.
Please do forgive my enthusiasm in helping you by the approach I would expect others to help me.

Thank you for your consideration and understanding.

Code
function run() {
    set(PARAMETERS);
    StartDate = 20190101;
    BarPeriod = 60;
    Capital = 2000;
    LookBack = 150;

    vars Open = series(priceOpen());
    vars High = series(priceHigh());
    vars Low = series(priceLow());
    vars Close = series(priceClose());

    // Additional input: normalized close
    vars NormClose = series(Close[0] / 100);

    int NumSignals = 5; // Number of total input signals
    vars Signals = series(NumSignals);

    // Manually calculate the change for each series
    Signals[0] = Open[0] - Open[1]; // Change for Open
    Signals[1] = High[0] - High[1]; // Change for High
    Signals[2] = Low[0] - Low[1];  // Change for Low
    Signals[3] = Close[0] - Close[1]; // Change for Close
    Signals[4] = NormClose[0]; // Normalized Close

    var vLong, vShort, Threshold = 0.5;
    set(LOGFILE | PLOTNOW);

    // Advise functions with the signal array
    if (adviseLong(NEURAL + BALANCED, 0, Signals, NumSignals) > Threshold)
        enterLong();
    if (adviseShort(NEURAL + BALANCED, 0, Signals, NumSignals) > Threshold)
        enterShort();

    plot("Long", vLong, NEW|LINE, BLACK);
    plot("Short", vShort, LINE, GREY);
}


I hope this makes you happy... And Happy New Year to our challenging minds.

Last edited by TipmyPip; 01/01/24 22:31.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: DeepLearn, introduce new feature [Re: NewtraderX] #488034
01/02/24 07:20
01/02/24 07:20
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
Well, there are even more sophisticated approaches, that need even more modifications.
Please accept my apology as I am learning new ideas, to contribute to our community of creative thinking. Thank you.

Code
function run() {
    set(PARAMETERS);
    StartDate = 20190101;
    BarPeriod = 60;
    Capital = 2000;
    LookBack = 150;

    vars Open = series(priceOpen());
    vars High = series(priceHigh());
    vars Low = series(priceLow());
    vars Close = series(priceClose());
    vars NormClose = series(Close[0] / 100);

    int NumSignalsFirstLayer = 5; // Number of signals for the first neural network
    vars SignalsFirstLayer = series(NumSignalsFirstLayer);

    SignalsFirstLayer[0] = Open[0] - Open[1];
    SignalsFirstLayer[1] = High[0] - High[1];
    SignalsFirstLayer[2] = Low[0] - Low[1];
    SignalsFirstLayer[3] = Close[0] - Close[1];
    SignalsFirstLayer[4] = NormClose[0];

    // Outputs from the first layer
    var LongOutputFirstLayer = adviseLong(NEURAL + BALANCED, 0, SignalsFirstLayer, NumSignalsFirstLayer);
    var ShortOutputFirstLayer = adviseShort(NEURAL + BALANCED, 0, SignalsFirstLayer, NumSignalsFirstLayer);

    int NumSignalsSecondLayer = 2; // Number of signals for the second neural network
    vars SignalsSecondLayer = series(NumSignalsSecondLayer);

    // Use the outputs from the first layer as inputs for the second layer
    SignalsSecondLayer[0] = LongOutputFirstLayer;
    SignalsSecondLayer[1] = ShortOutputFirstLayer;

    var vLong, vShort, Threshold = 0.5;
    set(LOGFILE | PLOTNOW);

    if (adviseLong(NEURAL + BALANCED, 0, SignalsSecondLayer, NumSignalsSecondLayer) > Threshold)
        enterLong();
    if (adviseShort(NEURAL + BALANCED, 0, SignalsSecondLayer, NumSignalsSecondLayer) > Threshold)
        enterShort();

    plot("Long", vLong, NEW|LINE, BLACK);
    plot("Short", vShort, LINE, GREY);
}

Last edited by TipmyPip; 01/02/24 07:25.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: DeepLearn, introduce new feature [Re: NewtraderX] #488035
01/02/24 07:38
01/02/24 07:38
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
Or Even More complex structures. The Below code is only a basic framework for the development of a higher level of interconnected networks:

Code
function run() {
    set(PARAMETERS);
    StartDate = 20190101;
    BarPeriod = 60;
    Capital = 2000;
    LookBack = 150;

    vars Open = series(priceOpen());
    vars High = series(priceHigh());
    vars Low = series(priceLow());
    vars Close = series(priceClose());
    vars NormClose = series(Close[0] / 100);

    // First layer signals - Using DTREE
    int NumSignalsDTREE = 5;
    vars SignalsDTREE = series(NumSignalsDTREE);

    SignalsDTREE[0] = Open[0] - Open[1];
    SignalsDTREE[1] = High[0] - High[1];
    SignalsDTREE[2] = Low[0] - Low[1];
    SignalsDTREE[3] = Close[0] - Close[1];
    SignalsDTREE[4] = NormClose[0];

    var DTreeLongOutput = adviseLong(DTREE, 0, SignalsDTREE, NumSignalsDTREE);
    var DTreeShortOutput = adviseShort(DTREE, 0, SignalsDTREE, NumSignalsDTREE);

    // Second layer signals - Using NEURAL
    int NumSignalsNEURAL = 2;
    vars SignalsNEURAL = series(NumSignalsNEURAL);

    SignalsNEURAL[0] = DTreeLongOutput;
    SignalsNEURAL[1] = DTreeShortOutput;

    var vLong, vShort, Threshold = 0.5;
    set(LOGFILE | PLOTNOW);

    if (adviseLong(NEURAL + BALANCED, 0, SignalsNEURAL, NumSignalsNEURAL) > Threshold)
        enterLong();
    if (adviseShort(NEURAL + BALANCED, 0, SignalsNEURAL, NumSignalsNEURAL) > Threshold)
        enterShort();

    plot("Long", vLong, NEW|LINE, BLACK);
    plot("Short", vShort, LINE, GREY);
}


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: DeepLearn, introduce new feature [Re: TipmyPip] #488048
01/03/24 03:16
01/03/24 03:16
Joined: Mar 2021
Posts: 35
Ocean county, Florida
NewtraderX Offline OP
Newbie
NewtraderX  Offline OP
Newbie

Joined: Mar 2021
Posts: 35
Ocean county, Florida
no worries,
as soon as I have time I will put some effort into digesting those scripts. Thanks.

Last edited by NewtraderX; 01/03/24 03:17.
Re: DeepLearn, introduce new feature [Re: NewtraderX] #488050
01/03/24 06:47
01/03/24 06:47
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
Thank you for giving me my kind enthusiasm :-) I guess this one will have problems with memory management.

Code
#define INPUTS_PER_MODEL 10
#define TOTAL_INPUTS 50  // Adjusted for additional volume data
#define NUM_MODELS 5     // Adjusted for the additional inputs

function run() {
    set(PARAMETERS);
    StartDate = 20190101;
    BarPeriod = 60;
    Capital = 2000;
    LookBack = 20; // Increased LookBack to cover 10 previous bars

    vars Open = series(priceOpen());
    vars High = series(priceHigh());
    vars Low = series(priceLow());
    vars Close = series(priceClose());
    vars Volume = series(marketVol());

    // Define your 50 inputs including volume
    vars Inputs = series(TOTAL_INPUTS);
    int i;
    for(i = 0; i < 10; ++i) { // Previous 10 bars
        Inputs[i] = Open[i + 1];      // Past opens
        Inputs[i + 10] = High[i + 1];  // Past highs
        Inputs[i + 20] = Low[i + 1];   // Past lows
        Inputs[i + 30] = Close[i + 1]; // Past closes
        Inputs[i + 40] = Volume[i + 1]; // Past volumes
    }

    // Divide inputs among five neural networks
    var ModelInputs[NUM_MODELS][INPUTS_PER_MODEL];
    int i;
    for(i = 0; i < TOTAL_INPUTS; ++i) {
        ModelInputs[i / INPUTS_PER_MODEL][i % INPUTS_PER_MODEL] = Inputs[i];
    }

    vars ModelOutputs[NUM_MODELS];
    int i;
    var ModelLongOutputs[NUM_MODELS];
    var ModelShortOutputs[NUM_MODELS];
    for(i = 0; i < NUM_MODELS; ++i) {
        ModelLongOutputs[i] = adviseLong(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
        ModelShortOutputs[i] = adviseShort(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
    }

    var CombinedLongSignal = 0;
    var CombinedShortSignal = 0;
    for(i = 0; i < NUM_MODELS; ++i) {
        CombinedLongSignal += ModelLongOutputs[i];
        CombinedShortSignal += ModelShortOutputs[i];
    }

    CombinedLongSignal /= NUM_MODELS;
    CombinedShortSignal /= NUM_MODELS;

    var Threshold = 0.5;
    set(LOGFILE | PLOTNOW);
    if (CombinedLongSignal > Threshold)
        enterLong();
    if (CombinedShortSignal > Threshold)
        enterShort();

    plot("Long Signal", CombinedLongSignal, NEW|LINE, BLACK);
    plot("Short Signal", CombinedShortSignal, NEW|LINE, RED);
}


Last edited by TipmyPip; 01/03/24 07:07.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: DeepLearn, introduce new feature [Re: NewtraderX] #488051
01/03/24 07:19
01/03/24 07:19
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
And this one will be even more sophisticated :-) but the limits of your imagination for the inputs, and the structures of the networks are only a function of time :-)

Code
#define INPUTS_PER_MODEL 10
#define TOTAL_INPUTS 50  // Adjusted for additional volume data
#define NUM_MODELS 5     // Number of models in the first layer
#define FINAL_LAYER_INPUTS NUM_MODELS * 2  // Each model contributes two signals (long and short)

function run() {
    set(PARAMETERS);
    StartDate = 20190101;
    BarPeriod = 60;
    Capital = 2000;
    LookBack = 20; 

    vars Open = series(priceOpen());
    vars High = series(priceHigh());
    vars Low = series(priceLow());
    vars Close = series(priceClose());
    vars Volume = series(marketVol());

    // Define your inputs including volume
    vars Inputs = series(TOTAL_INPUTS);
	 int i;
    for(i = 0; i < 10; ++i) {
        Inputs[i] = Open[i + 1];
        Inputs[i + 10] = High[i + 1];
        Inputs[i + 20] = Low[i + 1];
        Inputs[i + 30] = Close[i + 1];
        Inputs[i + 40] = Volume[i + 1];
    }

    // Divide inputs among neural networks
    var ModelInputs[NUM_MODELS][INPUTS_PER_MODEL];
	 int i;
    for(i = 0; i < TOTAL_INPUTS; ++i) {
        ModelInputs[i / INPUTS_PER_MODEL][i % INPUTS_PER_MODEL] = Inputs[i];
    }

    vars ModelLongOutputs = series(NUM_MODELS);
    vars ModelShortOutputs = series(NUM_MODELS);
	 int i;
    for(i = 0; i < NUM_MODELS; ++i) {
        ModelLongOutputs[i] = adviseLong(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
        ModelShortOutputs[i] = adviseShort(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
    }

    // Second layer of neural network
    vars FinalInputs = series(FINAL_LAYER_INPUTS);
	 int i;
    for(i = 0; i < NUM_MODELS; ++i) {
        FinalInputs[i] = ModelLongOutputs[i];
        FinalInputs[i + NUM_MODELS] = ModelShortOutputs[i]; // Offset by NUM_MODELS
    }

    var FinalLongSignal = adviseLong(NEURAL + BALANCED, 0, FinalInputs, FINAL_LAYER_INPUTS);
    var FinalShortSignal = adviseShort(NEURAL + BALANCED, 0, FinalInputs, FINAL_LAYER_INPUTS);
    var Threshold = 0.5;

    set(LOGFILE | PLOTNOW);
    if (FinalLongSignal > Threshold)
        enterLong();
    if (FinalShortSignal > Threshold)
        enterShort();

    plot("Final Long Signal", FinalLongSignal, NEW|LINE, BLACK);
    plot("Final Short Signal", FinalShortSignal, LINE, RED);
}


In addition, may be Inputting the data in a different manner will cause the networks to respond differently:

Code
// Define your inputs including volume
    vars Inputs = series(TOTAL_INPUTS);
	 int i;
    for(i = 0; i < LookBack; ++i) {
        Inputs[i * 5 + 0] = Open[i];
        Inputs[i * 5 + 1] = High[i];
        Inputs[i * 5 + 2] = Low[i];
        Inputs[i * 5 + 3] = Close[i];
        Inputs[i * 5 + 4] = Volume[i];
    }


Last edited by TipmyPip; 01/03/24 07:33.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: DeepLearn, introduce new feature [Re: NewtraderX] #488083
01/09/24 11:47
01/09/24 11:47
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
Deep Learning idea with Multi-Layer Neural Network:

Code
#define INPUTS_PER_MODEL 10
#define TOTAL_INPUTS 50  // Adjusted for additional volume data
#define NUM_MODELS 5     // Number of models in the first layer
#define FINAL_LAYER_INPUTS NUM_MODELS * 2  // Each model contributes two signals (long and short)
#define SECOND_LAYER_INPUTS 6 // Inputs for the second layer

var change(int n) {
    return scale((priceClose(0) - priceClose(n)) / priceClose(0), 100) / 100;
}

var range(int n) {
    return scale((HH(n) - LL(n)) / priceClose(0), 100) / 100;
}

function run() {
    set(PARAMETERS);
    StartDate = 20190101;
    BarPeriod = 60;
    Capital = 2000;
    LookBack = 120;

    vars Open = series(priceOpen());
    vars High = series(priceHigh());
    vars Low = series(priceLow());
    vars Close = series(priceClose());
    vars Volume = series(marketVol());

    // First layer: NEURAL models
    vars Inputs = series(TOTAL_INPUTS);
	 int i;
    for(i = 0; i < LookBack; ++i) {
        Inputs[i * 5 + 0] = Open[i];
        Inputs[i * 5 + 1] = High[i];
        Inputs[i * 5 + 2] = Low[i];
        Inputs[i * 5 + 3] = Close[i];
        Inputs[i * 5 + 4] = Volume[i];
    }

    var ModelInputs[NUM_MODELS][INPUTS_PER_MODEL];
	 int i;
    for(i = 0; i < TOTAL_INPUTS; ++i) {
        ModelInputs[i % NUM_MODELS][i / NUM_MODELS] = Inputs[i];
    }

    vars ModelLongOutputs = series(NUM_MODELS);
    vars ModelShortOutputs = series(NUM_MODELS);
	 int i;
    for(i = 0; i < NUM_MODELS; ++i) {
        ModelLongOutputs[i] = adviseLong(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
        ModelShortOutputs[i] = adviseShort(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
    }

    // Second layer: change, range, and pattern-based signals
    vars SecondLayerInputs = series(SECOND_LAYER_INPUTS);
    SecondLayerInputs[0] = change(2);
    SecondLayerInputs[1] = range(2);
    SecondLayerInputs[2] = adviseLong(PATTERN + 2 + RETURNS, 0, priceH(2), priceL(2), priceC(2), priceH(1), priceL(1), priceC(1), priceH(1), priceL(1), priceC(1), priceH(0), priceL(0), priceC(0));

    // Third layer: Final decision neural network
    vars FinalInputs = series(FINAL_LAYER_INPUTS + SECOND_LAYER_INPUTS);
	 int i;
    for(i = 0; i < NUM_MODELS; ++i) {
        FinalInputs[i * 2 + 0] = ModelLongOutputs[i];
        FinalInputs[i * 2 + 1] = ModelShortOutputs[i];
    }
    for(i = 0; i < SECOND_LAYER_INPUTS; ++i) {
        FinalInputs[FINAL_LAYER_INPUTS + i] = SecondLayerInputs[i];
    }

    var FinalLongSignal = adviseLong(NEURAL + BALANCED, 0, FinalInputs, FINAL_LAYER_INPUTS + SECOND_LAYER_INPUTS);
    var FinalShortSignal = adviseShort(NEURAL + BALANCED, 0, FinalInputs, FINAL_LAYER_INPUTS + SECOND_LAYER_INPUTS);
    var Threshold = 0.5;

    set(LOGFILE | PLOTNOW);
    if (FinalLongSignal > Threshold)
        enterLong();
    if (FinalShortSignal > Threshold)
        enterShort();

    plot("Final Long Signal", FinalLongSignal, NEW|LINE, BLACK);
    plot("Final Short Signal", FinalShortSignal, LINE, RED);
}


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: DeepLearn, introduce new feature [Re: NewtraderX] #488084
01/10/24 10:57
01/10/24 10:57
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
Here is a Neural Combination of Fuzzy Trading, Which can be improved : (Please note that memory is required and more optimization and testing is needed)

Code
#define INPUTS_PER_MODEL 10
#define TOTAL_INPUTS 50  // Adjusted for additional volume data
#define NUM_MODELS 5     // Number of models in the first layer
#define FINAL_LAYER_INPUTS NUM_MODELS * 2  // Each model contributes two signals (long and short)
#define SECOND_LAYER_INPUTS 18 // Adjusted for additional fuzzy inputs

var change(int n) {
    return scale((priceClose(0) - priceClose(n)) / priceClose(0), 100) / 100;
}

var range(int n) {
    return scale((HH(n) - LL(n)) / priceClose(0), 100) / 100;
}

function run() {
    set(PARAMETERS);
    StartDate = 20190101;
    BarPeriod = 60;
    Capital = 2000;
    LookBack = 120;

    vars Open = series(priceOpen());
    vars High = series(priceHigh());
    vars Low = series(priceLow());
    vars Close = series(priceClose());
    vars Volume = series(marketVol());

    // First layer: NEURAL models
    vars Inputs = series(TOTAL_INPUTS);
	 int i;
    for(i = 0; i < LookBack; ++i) {
        Inputs[i * 5 + 0] = Open[i];
        Inputs[i * 5 + 1] = High[i];
        Inputs[i * 5 + 2] = Low[i];
        Inputs[i * 5 + 3] = Close[i];
        Inputs[i * 5 + 4] = Volume[i];
    }

    var ModelInputs[NUM_MODELS][INPUTS_PER_MODEL];
	 int i;
    for(i = 0; i < TOTAL_INPUTS; ++i) {
        ModelInputs[i % NUM_MODELS][i / NUM_MODELS] = Inputs[i];
    }

    vars ModelLongOutputs = series(NUM_MODELS);
    vars ModelShortOutputs = series(NUM_MODELS);
	 int i;
    for(i = 0; i < NUM_MODELS; ++i) {
        ModelLongOutputs[i] = adviseLong(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
        ModelShortOutputs[i] = adviseShort(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
    }

    // Second layer: change, range, pattern-based signals, and fuzzy logic
    vars SecondLayerInputs = series(SECOND_LAYER_INPUTS);
    SecondLayerInputs[0] = change(2);
    SecondLayerInputs[1] = range(2);
    SecondLayerInputs[2] = adviseLong(PATTERN + 2 + RETURNS, 0, priceH(2), priceL(2), priceC(2), priceH(1), priceL(1), priceC(1), priceH(1), priceL(1), priceC(1), priceH(0), priceL(0), priceC(0));
    // Fuzzy logic signals
    SecondLayerInputs[3] = equalF(Close[0], Close[1]);
    SecondLayerInputs[4] = aboveF(Close[0], Close[1]);
    SecondLayerInputs[5] = belowF(Close[0], Close[1]);
    SecondLayerInputs[6] = betweenF(Close[0], LL(10), HH(10));
    SecondLayerInputs[7] = peakF(Close);
    SecondLayerInputs[8] = valleyF(Close);
    SecondLayerInputs[9] = risingF(Close);
    SecondLayerInputs[10] = fallingF(Close);
    SecondLayerInputs[11] = crossOverF(Close, SMA(Close, 10));
    SecondLayerInputs[12] = crossUnderF(Close, SMA(Close, 10));
    SecondLayerInputs[13] = andF(risingF(Close), fallingF(Open));
    SecondLayerInputs[14] = orF(risingF(Close), fallingF(Open));
    SecondLayerInputs[15] = notF(risingF(Close));
    SecondLayerInputs[16] = crossOverF(Close, Open);
    SecondLayerInputs[17] = crossUnderF(Close, Open);

    // Third layer: Final decision neural network
    vars FinalInputs = series(FINAL_LAYER_INPUTS + SECOND_LAYER_INPUTS);
	 int i;
    for(i = 0; i < NUM_MODELS; ++i) {
        FinalInputs[i * 2 + 0] = ModelLongOutputs[i];
        FinalInputs[i * 2 + 1] = ModelShortOutputs[i];
    }
    for( i = 0; i < SECOND_LAYER_INPUTS; ++i) {
        FinalInputs[FINAL_LAYER_INPUTS + i] = SecondLayerInputs[i];
    }

    var FinalLongSignal = adviseLong(NEURAL + BALANCED, 0, FinalInputs, FINAL_LAYER_INPUTS + SECOND_LAYER_INPUTS);
    var FinalShortSignal = adviseShort(NEURAL + BALANCED, 0, FinalInputs, FINAL_LAYER_INPUTS + SECOND_LAYER_INPUTS);
    var Threshold = 0.5;

    set(LOGFILE | PLOTNOW);
    if (FinalLongSignal > Threshold)
        enterLong();
    if (FinalShortSignal > Threshold)
        enterShort();

    plot("Final Long Signal", FinalLongSignal, NEW|LINE, BLACK);
    plot("Final Short Signal", FinalShortSignal, LINE, RED);
}

Last edited by TipmyPip; 01/10/24 10:58.

ZorroTraderGPT - https://bit.ly/3Gbsm4S
Re: DeepLearn, introduce new feature [Re: NewtraderX] #488085
01/10/24 11:31
01/10/24 11:31
Joined: Sep 2017
Posts: 82
T
TipmyPip Online
Junior Member
TipmyPip  Online
Junior Member
T

Joined: Sep 2017
Posts: 82
Some ideas of the different Network architectures can perform at a higher accuracy:

Code
#define INPUTS_PER_MODEL 10
#define TOTAL_INPUTS 50  // Adjusted for additional volume data
#define NUM_MODELS 5     // Number of models in the first layer
#define FINAL_LAYER_INPUTS NUM_MODELS * 2  // Each model contributes two signals (long and short)
#define SECOND_LAYER_INPUTS 18 // Adjusted for additional fuzzy inputs

var change(int n) {
    return scale((priceClose(0) - priceClose(n)) / priceClose(0), 100) / 100;
}

var range(int n) {
    return scale((HH(n) - LL(n)) / priceClose(0), 100) / 100;
}

function run() {
    set(PARAMETERS);
    StartDate = 20190101;
    BarPeriod = 60;
    Capital = 2000;
    LookBack = 120;

    vars Open = series(priceOpen());
    vars High = series(priceHigh());
    vars Low = series(priceLow());
    vars Close = series(priceClose());
    vars Volume = series(marketVol());

    // First layer: NEURAL models
    vars Inputs = series(TOTAL_INPUTS);
	 int i;
    for(i = 0; i < LookBack; ++i) {
        Inputs[i * 5 + 0] = Open[i];
        Inputs[i * 5 + 1] = High[i];
        Inputs[i * 5 + 2] = Low[i];
        Inputs[i * 5 + 3] = Close[i];
        Inputs[i * 5 + 4] = Volume[i];
    }

    var ModelInputs[NUM_MODELS][INPUTS_PER_MODEL];
	 int i;
    for(i = 0; i < TOTAL_INPUTS; ++i) {
        ModelInputs[i % NUM_MODELS][i / NUM_MODELS] = Inputs[i];
    }

    vars ModelLongOutputs = series(NUM_MODELS);
    vars ModelShortOutputs = series(NUM_MODELS);
	 int i;
    for(i = 0; i < NUM_MODELS; ++i) {
        ModelLongOutputs[i] = adviseLong(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
        ModelShortOutputs[i] = adviseShort(NEURAL + BALANCED, 0, &ModelInputs[i][0], INPUTS_PER_MODEL);
    }

    // Second layer: change, range, pattern-based signals, and fuzzy logic based on change and range
    vars SecondLayerInputs = series(SECOND_LAYER_INPUTS);
    var ChangeValue = change(2);
    var RangeValue = range(2);

    SecondLayerInputs[0] = ChangeValue;
    SecondLayerInputs[1] = RangeValue;
    SecondLayerInputs[2] = adviseLong(PATTERN + 2 + RETURNS, 0, priceH(2), priceL(2), priceC(2), priceH(1), priceL(1), priceC(1), priceH(1), priceL(1), priceC(1), priceH(0), priceL(0), priceC(0));
    SecondLayerInputs[3] = equalF(ChangeValue, RangeValue);
    SecondLayerInputs[4] = aboveF(ChangeValue, RangeValue);
    SecondLayerInputs[5] = belowF(ChangeValue, RangeValue);
    SecondLayerInputs[6] = betweenF(ChangeValue, RangeValue - 0.1, RangeValue + 0.1);
    SecondLayerInputs[7] = peakF(series(ChangeValue));
    SecondLayerInputs[8] = valleyF(series(ChangeValue));
    SecondLayerInputs[9] = risingF(series(ChangeValue));
    SecondLayerInputs[10] = fallingF(series(ChangeValue));
    SecondLayerInputs[11] = crossOverF(series(ChangeValue), series(RangeValue));
    SecondLayerInputs[12] = crossUnderF(series(ChangeValue), series(RangeValue));
    SecondLayerInputs[13] = andF(aboveF(ChangeValue, 0), belowF(RangeValue, 0.5));
    SecondLayerInputs[14] = orF(aboveF(ChangeValue, 0), belowF(RangeValue, 0.5));
    SecondLayerInputs[15] = notF(aboveF(ChangeValue, 0));
    SecondLayerInputs[16] = crossOverF(series(ChangeValue), series(0));
    SecondLayerInputs[17] = crossUnderF(series(ChangeValue), series(0));

    // Third layer: Final decision neural network
    vars FinalInputs = series(FINAL_LAYER_INPUTS + SECOND_LAYER_INPUTS);
	 int i;
    for(i = 0; i < NUM_MODELS; ++i) {
        FinalInputs[i * 2 + 0] = ModelLongOutputs[i];
        FinalInputs[i * 2 + 1] = ModelShortOutputs[i];
    }
	 int i;
    for(i = 0; i < SECOND_LAYER_INPUTS; ++i) {
        FinalInputs[FINAL_LAYER_INPUTS + i] = SecondLayerInputs[i];
    }

    var FinalLongSignal = adviseLong(NEURAL + BALANCED, 0, FinalInputs, FINAL_LAYER_INPUTS + SECOND_LAYER_INPUTS);
    var FinalShortSignal = adviseShort(NEURAL + BALANCED, 0, FinalInputs, FINAL_LAYER_INPUTS + SECOND_LAYER_INPUTS);
    var Threshold = 0.5;

    set(LOGFILE | PLOTNOW);
    if (FinalLongSignal > Threshold)
        enterLong();
    if (FinalShortSignal > Threshold)
        enterShort();

    plot("Final Long Signal", FinalLongSignal, NEW|LINE, BLACK);
    plot("Final Short Signal", FinalShortSignal, LINE, RED);
}


ZorroTraderGPT - https://bit.ly/3Gbsm4S
Page 1 of 2 1 2

Moderated by  Petra 

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