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