2 registered members (SBGuy, Quad),
768
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: DeepLearn, introduce new feature
[Re: NewtraderX]
#488051
01/03/24 07:19
01/03/24 07:19
|
Joined: Sep 2017
Posts: 82
TipmyPip
Junior Member
|
Junior Member
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 :-) #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: // 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.
|
|
|
Re: DeepLearn, introduce new feature
[Re: NewtraderX]
#488083
01/09/24 11:47
01/09/24 11:47
|
Joined: Sep 2017
Posts: 82
TipmyPip
Junior Member
|
Junior Member
Joined: Sep 2017
Posts: 82
|
Deep Learning idea with Multi-Layer Neural Network: #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);
}
|
|
|
Re: DeepLearn, introduce new feature
[Re: NewtraderX]
#488084
01/10/24 10:57
01/10/24 10:57
|
Joined: Sep 2017
Posts: 82
TipmyPip
Junior Member
|
Junior Member
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) #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.
|
|
|
Re: DeepLearn, introduce new feature
[Re: NewtraderX]
#488085
01/10/24 11:31
01/10/24 11:31
|
Joined: Sep 2017
Posts: 82
TipmyPip
Junior Member
|
Junior Member
Joined: Sep 2017
Posts: 82
|
Some ideas of the different Network architectures can perform at a higher accuracy: #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);
}
|
|
|
|