add supports for zone recovery ...

This commit is contained in:
2024-06-15 23:37:33 +03:30
parent f1edb81a7e
commit 69393d6d83
5 changed files with 872 additions and 32 deletions
+254 -19
View File
@@ -20,7 +20,8 @@
#property strict
//
#include "../Classes/x-saherelm.xczone.class.mq5"
// Imports ...
#include "../Classes/x-saherelm.xtrade.class.mq5"
//
#define ShortName "XNNTest"
@@ -39,14 +40,16 @@ input double w7 = 0.5;
input double w8 = 0.5;
input double w9 = 0.5;
//
input double eaVolume = 0.01;
//
// Variables ...
int barsTotal;
//
string mSymbol;
double mVolume;
ENUM_TIMEFRAMES mPeriod;
string eaSymbol;
ENUM_TIMEFRAMES eaPeriod;
//
// This is our Data Provider ...
@@ -54,11 +57,14 @@ int rsiHandler = INVALID_HANDLE;
double rsi[];
//
double inputs[]; // Storing Inputs
double weights[]; // Storing Weights;
double nnInputs[]; // Storing Inputs
double nnWeights[]; // Storing Weights;
//
double output; // Output Neuron Value
double nnOutput; // Output Neuron Value
//
XSCTrade *mTrader;
//
// Initialization ...
@@ -93,6 +99,10 @@ void OnDeinit(const int reason)
//
// De Initialize XSampleEA Providers ...
IndicatorRelease(rsiHandler);
ArrayFree(rsi);
ArrayFree(nnInputs);
ArrayFree(nnWeights);
}
//
@@ -100,17 +110,173 @@ void OnDeinit(const int reason)
void OnTick()
{
//
int bars = iBars(
_Symbol,
_Period //
XPosition positions[];
//
XPosition longs[];
int longsCount = 0;
//
XPosition shorts[];
int shortsCount = 0;
//
int positionsCount = mTrader.GetPositions(
positions //
);
if (barsTotal == bars)
if (IsValidSize(positionsCount))
{
return;
//
ExtractPositions(
positions,
longs,
shorts //
);
//
longsCount = ArraySize(longs);
shortsCount = ArraySize(shorts);
}
//
barsTotal = bars;
if (longsCount == 0 && shortsCount == 0)
{
//
double longEntry = GetEntry(eaSymbol, POSITION_TYPE_BUY);
mTrader.Buy(
eaSymbol,
eaPeriod,
eaVolume,
longEntry //
);
//
double shortEntry = GetEntry(eaSymbol, POSITION_TYPE_SELL);
mTrader.Sell(
eaSymbol,
eaPeriod,
eaVolume,
shortEntry //
);
}
//
return;
// int rsiCopiedData = CopyBuffer(
// rsiHandler,
// 0, // Line Index
// 1, // BarIndex
// 10, // Count
// rsi // Buffer
// );
// if (rsiCopiedData < 0)
// {
// //
// // Ignore Moving Forward when there isn't any Copied Data ...
// return;
// }
// //
// // Normalize Input Data ...
// double lower = 0;
// double upper = 1;
// //
// double max = rsi[ArrayMaximum(rsi)];
// double min = rsi[ArrayMinimum(rsi)];
// //
// ArrayFree(nnInputs);
// ArrayResize(nnInputs, 10);
// //
// for (int i = 0; i < ArraySize(rsi); i++)
// {
// nnInputs[i] = ((rsi[i] - min) * (upper - lower) / (max - min)) + lower;
// }
// //
// // Calculating Output ...
// nnOutput = CalculateNeuron(
// nnInputs,
// nnWeights //
// );
// //
// // Now we Can Use NN Output for Placing Trades ...
// //
// bool canBuy = nnOutput < 0.5;
// bool canSell = nnOutput >= 0.5;
// //
// XPosition positions[];
// XPosition longs[];
// XPosition shorts[];
// int positionsCount = mTrader.GetPositions(
// positions //
// );
// if (IsValidSize(positionsCount))
// {
// //
// ExtractPositions(
// positions,
// longs,
// shorts //
// );
// //
// if (canBuy)
// {
// //
// mTrader.Close(shorts, "Opposit");
// //
// if (ArraySize(longs) > 0)
// {
// return;
// }
// }
// else if (canSell)
// {
// //
// mTrader.Close(longs, "Opposit");
// //
// if (ArraySize(shorts) > 0)
// {
// return;
// }
// }
// }
// //
// double mEntry =
// canBuy
// ? GetEntry(eaSymbol, POSITION_TYPE_BUY)
// : GetEntry(eaSymbol, POSITION_TYPE_SELL);
// //
// if (canBuy)
// {
// //
// mTrader.Buy(
// eaSymbol,
// eaPeriod,
// eaVolume,
// mEntry //
// );
// }
// else if (canSell)
// {
// //
// mTrader.Sell(
// eaSymbol,
// eaPeriod,
// eaVolume,
// mEntry //
// );
// }
}
//
@@ -123,22 +289,48 @@ bool InitialEA()
bool result = false;
//
mSymbol = _Symbol;
mPeriod = _Period;
eaSymbol = _Symbol;
eaPeriod = _Period;
//
// Initialize RSI Handler ...
rsiHandler = iRSI(
mSymbol,
mPeriod,
eaSymbol,
eaPeriod,
14,
PRICE_CLOSE //
);
result = rsiHandler != INVALID_HANDLE;
if (!result) {
if (!result)
{
return result;
}
//
mTrader = new XSCTrade(
1,
78692110 //
);
//
ArraySetAsSeries(rsi, true);
//
ArrayResize(nnWeights, 10);
//
// Filling Weights Buffer ...
nnWeights[0] = w0;
nnWeights[1] = w1;
nnWeights[2] = w2;
nnWeights[3] = w3;
nnWeights[4] = w4;
nnWeights[5] = w5;
nnWeights[6] = w6;
nnWeights[7] = w7;
nnWeights[8] = w8;
nnWeights[9] = w9;
//
result = true;
@@ -146,4 +338,47 @@ bool InitialEA()
return result;
}
//
//
// Activation Function ...
double Activate(double neuron)
{
//
double result = 0;
//
result = 1 / (1 + exp(-neuron));
//
return result;
}
//
// Calculating Neuron ...
// NET Inputs ...
double CalculateNeuron(
double &x[], // Inputs
double &w[] // Weights
)
{
//
double result = 0;
//
double netInput = 0;
for (int i = 0; i < ArraySize(x); i++)
{
//
netInput += x[i] * w[i];
}
//
// Change The Shape of Sigmoid Graph for Smoothing ...
netInput *= 0.4;
//
// Calculate Activated Result ...
result = Activate(netInput);
//
return result;
}
+13 -4
View File
@@ -49,15 +49,18 @@ input bool x121EAGetVerificationFromOtherTimeFrames = true; // Get Verifications
// Risk Management ...
input group "Risk Management";
input double x121EAVolume = 0.01; // Static Volume
input double x121EATPPoint = 60; // TP Point
input double x121EASLPoint = 300; // SL Point
input double x121EATPPoint = 100; // TP Point
input double x121EASLPoint = 100; // SL Point
input int x121EAMaxAllowedTrades = 1; // Max Allowed Positions
input bool x121EAIgnoreSL = true; // Ignore Calculated SL
input bool x121EAIgnoreSL = false; // Ignore Calculated SL
input bool x121EAIgnoreTP = false; // Ignore Calculated TP
input bool x121EAUseSupport = false; // Use Support Signals
input bool x121EAAllowGrid = true; // Allow Grid Signals
input bool x121EAAllowGrid = false; // Allow Grid Signals
input double x121EAGridDistance = 100; // Grid Distance
input double x121EAGridVolumeMultiplier = 2; // Grid Volume Multiplier
input bool x121EAAllowRecovery = true; // Allow Recovery Signals
input double x121EARecoveryDistance = 100; // Recovery Distance
input double x121EARecoveryVolumeMultiplier = 2; // Recovery Volume Multiplier
input double x121EAMinRequiredProfitPerTrade = 0.5; // Minimum Required Profit for Hedging
input double x121EAMinRequiredProfitPerVolumeFactor = 0.01; // Minimum Required Profit for Hedging Per Volume
input int x121EARestingAfterHedge = 300; // Resting Seconds After Hedge
@@ -195,6 +198,12 @@ bool InitialEA()
x121EA.GridDistance(x121EAGridDistance);
x121EA.GridVolumeMultiplier(x121EAGridVolumeMultiplier);
//
// Recovery System ...
x121EA.AllowRecovery(x121EAAllowRecovery);
x121EA.RecoveryDistance(x121EARecoveryDistance);
x121EA.RecoveryVolumeMultiplier(x121EARecoveryVolumeMultiplier);
//
// Configure Alert ...
x121EA.SetAlertPrefix(ShortName);