Initial Commit ...
This commit is contained in:
@@ -0,0 +1,134 @@
|
|||||||
|
# Candlestick Patters
|
||||||
|
|
||||||
|
## Doji
|
||||||
|
|
||||||
|
X_CT_DOJI
|
||||||
|
|
||||||
|
- Continue Trend
|
||||||
|
- Maybe end of a Trend
|
||||||
|
|
||||||
|
## Evening Star
|
||||||
|
|
||||||
|
X_CT_EVENING_STAR
|
||||||
|
|
||||||
|
- Bearish
|
||||||
|
- End of Bullish Trend
|
||||||
|
|
||||||
|
## Morning Star
|
||||||
|
|
||||||
|
X_CT_MORNING_STAR
|
||||||
|
|
||||||
|
- Bullish
|
||||||
|
- End of Bearish Trend
|
||||||
|
|
||||||
|
## Shooting Star
|
||||||
|
|
||||||
|
X_CT_SHOOTING_STAR
|
||||||
|
|
||||||
|
- Bearish
|
||||||
|
- End of Bullish Trend
|
||||||
|
|
||||||
|
## Hammer
|
||||||
|
|
||||||
|
X_CT_HAMMER
|
||||||
|
|
||||||
|
- Bullish
|
||||||
|
- End of Bearish Trend
|
||||||
|
|
||||||
|
## Inverted Hammer
|
||||||
|
|
||||||
|
X_CT_INVERTED_HAMMER
|
||||||
|
|
||||||
|
- Bullish
|
||||||
|
- End of Bearish Trend
|
||||||
|
|
||||||
|
## Bearish Harami
|
||||||
|
|
||||||
|
X_CT_BEARISH_HARAMI
|
||||||
|
|
||||||
|
- Bearish
|
||||||
|
- End Of Bullish Trend
|
||||||
|
|
||||||
|
## Bullish Harami
|
||||||
|
|
||||||
|
X_CT_BULLISH_HARAMI
|
||||||
|
|
||||||
|
- Bullish
|
||||||
|
- End of Bearish Trend
|
||||||
|
|
||||||
|
## Bearish Engulfing
|
||||||
|
|
||||||
|
X_CT_BEARISH_ENGULFING
|
||||||
|
|
||||||
|
- Bearish
|
||||||
|
- End of Bullish Trend
|
||||||
|
|
||||||
|
## Bullish Engulfing
|
||||||
|
|
||||||
|
X_CT_BULLISH_ENGULFING
|
||||||
|
|
||||||
|
- Bullish
|
||||||
|
- End of Bearish Trend
|
||||||
|
|
||||||
|
## Piercing Line
|
||||||
|
|
||||||
|
X_CT_PRICE_LINE
|
||||||
|
|
||||||
|
- Bearish
|
||||||
|
- End of Bullish Trend
|
||||||
|
|
||||||
|
## Bullish Belt
|
||||||
|
|
||||||
|
X_CT_BULLISH_BELT
|
||||||
|
|
||||||
|
- Bullish
|
||||||
|
- End of Bearish Trend
|
||||||
|
|
||||||
|
## Bullish Kicker
|
||||||
|
|
||||||
|
X_CT_BULLISH_KICKER
|
||||||
|
|
||||||
|
- Bullish
|
||||||
|
- End of Bearish Trend
|
||||||
|
|
||||||
|
## Bearish Kicker
|
||||||
|
|
||||||
|
X_CT_BEARISH_KICKER
|
||||||
|
|
||||||
|
- Bearish
|
||||||
|
- End of Bullish Trend
|
||||||
|
|
||||||
|
## Hanging Man
|
||||||
|
|
||||||
|
X_CT_HANGING_MAN
|
||||||
|
|
||||||
|
- Bearish
|
||||||
|
- End of Bullish Trend
|
||||||
|
|
||||||
|
## Dark Cloud Cover
|
||||||
|
|
||||||
|
X_CT_DARK_CLOUD_COVER
|
||||||
|
|
||||||
|
- Bearish
|
||||||
|
- End of Bullish Trend
|
||||||
|
|
||||||
|
## Bullish Candles
|
||||||
|
|
||||||
|
X_CT_HAMMER
|
||||||
|
X_CT_BULLISH_BELT
|
||||||
|
X_CT_MORNING_STAR
|
||||||
|
X_CT_BULLISH_KICKER
|
||||||
|
X_CT_BULLISH_HARAMI
|
||||||
|
X_CT_INVERTED_HAMMER
|
||||||
|
X_CT_BULLISH_ENGULFING
|
||||||
|
|
||||||
|
## Bearish Candles
|
||||||
|
|
||||||
|
X_CT_PRICE_LINE
|
||||||
|
X_CT_HANGING_MAN
|
||||||
|
X_CT_EVENING_STAR
|
||||||
|
X_CT_SHOOTING_STAR
|
||||||
|
X_CT_BEARISH_HARAMI
|
||||||
|
X_CT_BEARISH_KICKER
|
||||||
|
X_CT_DARK_CLOUD_COVER
|
||||||
|
X_CT_BEARISH_ENGULFING
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
# EMA
|
||||||
|
|
||||||
|
The EMA is designed to improve on the idea of an SMA by giving more weight to the most recent price data, which is considered to be more relevant than older data. Since new data carries greater weight, the EMA responds more quickly to price changes than the SMA does.
|
||||||
|
|
||||||
|
## Fromula
|
||||||
|
|
||||||
|
EMA = Price(t) × k + EMA(y) × (1−k)
|
||||||
|
|
||||||
|
where:
|
||||||
|
|
||||||
|
t = today
|
||||||
|
y = yesterday
|
||||||
|
N = number of days in EMA
|
||||||
|
k = 2 ÷ (N + 1)
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Ichimoku
|
||||||
|
|
||||||
|
1. **Conversion Line** (*tenkan sen*) => **9-PH+9-PL**/**2**
|
||||||
|
2. **Base Line** (*kijun sen*) => **26-PH + 26-PL**/**2**
|
||||||
|
3. **Leading Span A** (*senkou span A*) => **CL + Base Line**/**2**
|
||||||
|
4. **Leading Span B** (*senkou span B*) => **52-PH + 52-PL**/**2**
|
||||||
|
5. **Lagging Span** (*chikou span*) => **Close plotted 26 periods in the past**
|
||||||
|
|
||||||
|
## where
|
||||||
|
|
||||||
|
**PH** = Period high
|
||||||
|
**PL** = Period low
|
||||||
|
**CL** = Conversion line
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Angle
|
||||||
|
|
||||||
|
tan A = | (m - m’) / (1 + mm’ ) |
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# ArraySetAsSeries
|
||||||
|
|
||||||
|
The function sets the AS_SERIES flag to a selected object of a dynamic array, and elements will be indexed like in timeseries.
|
||||||
|
|
||||||
|
bool ArraySetAsSeries(
|
||||||
|
const void& array[], // array by reference
|
||||||
|
bool flag // true denotes reverse order of indexing
|
||||||
|
);
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
|
||||||
|
array[]
|
||||||
|
|
||||||
|
[in][out] Numeric array to set.
|
||||||
|
|
||||||
|
flag
|
||||||
|
|
||||||
|
[in] Array indexing direction.
|
||||||
|
|
||||||
|
Return Value
|
||||||
|
|
||||||
|
The function returns true on success, otherwise - false.
|
||||||
|
|
||||||
|
Note
|
||||||
|
|
||||||
|
The AS_SERIES flag can't be set for multi-dimensional arrays or static arrays (arrays, whose size in square brackets is preset already on the compilation stage). Indexing in timeseries differs from a common array in that the elements of timeseries are indexed from the end towards the beginning (from the newest to oldest data).
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Note on Bid and Ask
|
||||||
|
|
||||||
|
The Bid price is what you see on the MT4 charts, and the Ask price is just a few pips above the bid price, with the difference between them being the spread. We open buy orders and close sell orders on the Ask price; we open sell orders and close buy orders on the Bid price.
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
# BarIndex
|
||||||
|
|
||||||
|
in pine script bar_index reffers to current candle number, in reversal indexing.
|
||||||
|
in MQL for accessing bar_index to calculate indicator data, we have to do something like this:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated,
|
||||||
|
const datetime &time[],
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &low[],
|
||||||
|
const double &close[],
|
||||||
|
const long &tick_volume[],
|
||||||
|
const long &volume[],
|
||||||
|
const int &spread[])
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// here we define our limit ...
|
||||||
|
int limit = rates_total - prev_calculated;
|
||||||
|
|
||||||
|
//
|
||||||
|
// if our indicator requires some candles to pass as a length,
|
||||||
|
// and then start calculating by past passed values, by this way
|
||||||
|
// we are going to inform MQL Compiler, which do nothing, until
|
||||||
|
// required length passed ...
|
||||||
|
if(rates_total <= InpBullsPeriod) {
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// because bar index a zero start indexing system, for fixing
|
||||||
|
// qctual indexing in for loops, we have to call this ...
|
||||||
|
if(prev_calculated > 0) {
|
||||||
|
limit++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop through Bar Indexes ...
|
||||||
|
for(int i = 0; i < limit; i++) {
|
||||||
|
//
|
||||||
|
// Filling Exists Buffers, based on current Bar Index and required Conditions ...
|
||||||
|
ExtTempBuffer[i]=iMA(NULL,0,InpBullsPeriod,0,MODE_EMA,PRICE_CLOSE,i);
|
||||||
|
ExtBullsBuffer[i]=high[i]-ExtTempBuffer[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return(rates_total);
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,407 @@
|
|||||||
|
# CCI EA With SL and TP
|
||||||
|
|
||||||
|
this tutorial consists 5 part:
|
||||||
|
|
||||||
|
1. Create a CCI EA with SL and TP;
|
||||||
|
2. add a Moving Average Filter on a higher Timeframe;
|
||||||
|
3. add a Partial Close;
|
||||||
|
4. add a Break Event Stop;
|
||||||
|
5. Backtesting;
|
||||||
|
|
||||||
|
## Create a CCI EA with SL and TP
|
||||||
|
|
||||||
|
CCI is an Oscillator which provides some usefull data about iver baughts and over solds.
|
||||||
|
each of this situations can used as a signal.
|
||||||
|
|
||||||
|
the general idea in this tutorial is to use this states as a signal and then open and close positions based on them ...
|
||||||
|
|
||||||
|
Create a Expert Advisor and named it what you want.
|
||||||
|
|
||||||
|
now we have to read CCI data. create a pointer to it's iFunction and then create a buffer based on it on OnTick function.
|
||||||
|
we can now create a buy and sell conditions and check where this happens to open the positions.
|
||||||
|
|
||||||
|
the idea is when cci going above special level we get buy signal and when going below special level we get sell signal.
|
||||||
|
|
||||||
|
for implement this mechanism, first add two input for buyLevel and sellLevel and give them default values.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#include <Trade/Trade.mqh>
|
||||||
|
|
||||||
|
//
|
||||||
|
CTrade trader;
|
||||||
|
|
||||||
|
//
|
||||||
|
input double Lots = 1;
|
||||||
|
input double TpPoints = 100;
|
||||||
|
input double SlPoints = 100;
|
||||||
|
|
||||||
|
//
|
||||||
|
input double CciBuyLevel = -150;
|
||||||
|
input double CciSellLevel = 150;
|
||||||
|
|
||||||
|
//
|
||||||
|
int barsTotal;
|
||||||
|
|
||||||
|
//
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
barsTotal = iBars(_Symbol, CciTimeFrame);
|
||||||
|
|
||||||
|
//
|
||||||
|
OnTick();
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void OnTick() {
|
||||||
|
//
|
||||||
|
// for every single tick, we check current amount of bars
|
||||||
|
// for preventing double signaling on single bar ...
|
||||||
|
int bars = iBars(_Symbol, CciTimeframe);
|
||||||
|
if (barsTotal < bars) {
|
||||||
|
//
|
||||||
|
barsTotal = bars;
|
||||||
|
|
||||||
|
//
|
||||||
|
double cci[];
|
||||||
|
CopyBuffer(cciPointer, 0, 1, 2, cci);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buy Signal Condition ...
|
||||||
|
if (cci[1] < CciBuyLevel && cci[0] > CciBuyLevel) {
|
||||||
|
//
|
||||||
|
// Do Buy Trade ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// retrieve ask price ...
|
||||||
|
// since trader.Buy alway use market price (ask price) ...
|
||||||
|
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Normalize ask price ...
|
||||||
|
ask = NormalizeDouble(ask, _Digits);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating Tp based on Ask price ...
|
||||||
|
double tp = ask + TpPoints * _Point;
|
||||||
|
tp = NormalizeDouble(tp, _Digits);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating Sl based on Ask price ...
|
||||||
|
double sl = ask - SlPoints * _Point;
|
||||||
|
sl = NormalizeDouble(sl, _Digits);
|
||||||
|
|
||||||
|
//
|
||||||
|
trader.Buy(Lots, _Symbol, ask, sl, tp, "CCI Buy ...");
|
||||||
|
} else
|
||||||
|
//
|
||||||
|
// Sell Signal Condition ...
|
||||||
|
if (cci[1] > CciSellLevel && cci[0] < CciSellLevel) {
|
||||||
|
//
|
||||||
|
// Do Sell Trade ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// retrieve bid price ...
|
||||||
|
// since trader.Sell alway use market price (bid price) ...
|
||||||
|
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Normalize bid price ...
|
||||||
|
bid = NormalizeDouble(bid, _Digits);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating Tp based on Bid price ...
|
||||||
|
double tp = bid - TpPoints * _Point;
|
||||||
|
tp = NormalizeDouble(tp, _Digits);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating Sl based on Bid price ...
|
||||||
|
double sl = bid + SlPoints * _Point;
|
||||||
|
sl = NormalizeDouble(sl, _Digits);
|
||||||
|
|
||||||
|
//
|
||||||
|
trader.Sell(Lots, _Symbol, bid, sl, tp, "CCI Sell ...");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Show data on Chart side ...
|
||||||
|
Comment("\nCCI[0]: ", cci[0],
|
||||||
|
"\nCCI[1]: ", cci[1]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## add a Moving Average Filter on a higher Timeframe
|
||||||
|
|
||||||
|
moving average is another usefull indicator which provides a way to following market trend direction.
|
||||||
|
the idea is to accdept signals in direction of ma result.
|
||||||
|
so we have to implement Moving average in our EA then use it's values for filtering signals, this is what we call MA Verifications.
|
||||||
|
|
||||||
|
attached proper inputs related to MA Indicator to your advisor.
|
||||||
|
|
||||||
|
then create a Pointer(Handler) for iFunction of MA indicator.
|
||||||
|
|
||||||
|
we have to check for buy signals, that the ask price is above than moving average. and for sell signals the bid price is below than moving average, then if this conditions
|
||||||
|
are full filled, enter the positions.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
void OnTick() {
|
||||||
|
...
|
||||||
|
|
||||||
|
//
|
||||||
|
// reading ma series, buffer ...
|
||||||
|
double ma[];
|
||||||
|
CopyBuffer(maPointer, 0, 1, 1, ma);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buy Signal Condition ...
|
||||||
|
if (cci[1] < CciBuyLevel && cci[0] > CciBuyLevel) {
|
||||||
|
//
|
||||||
|
// Do Buy Trade ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// retrieve ask price ...
|
||||||
|
// since trader.Buy alway use market price (ask price) ...
|
||||||
|
double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filter by Moving Average ...
|
||||||
|
if (ask > ma[0]) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
//
|
||||||
|
// Sell Signal Condition ...
|
||||||
|
if (cci[1] > CciSellLevel && cci[0] < CciSellLevel) {
|
||||||
|
//
|
||||||
|
// Do Sell Trade ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// retrieve bid price ...
|
||||||
|
// since trader.Sell alway use market price (bid price) ...
|
||||||
|
double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filter by Moving Average ...
|
||||||
|
if (bid < ma[0]) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Show data on Chart side ...
|
||||||
|
Comment("\nCCI[0]: ", cci[0],
|
||||||
|
"\nCCI[1]: ", cci[1],
|
||||||
|
"\nMA[0]: ", ma[0],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## add a Partial Close
|
||||||
|
|
||||||
|
partial close positions is an idea to save money more than usual in trading exit strategy.
|
||||||
|
actually implementing CTrade instance provide this for us. and we can use it in our EAs.
|
||||||
|
|
||||||
|
in this section we are going to review how we can do it ...
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Define Some Inputs for Partial Close Positions Management ...
|
||||||
|
input int PartialClosePoints = 70;
|
||||||
|
input double PartialCloseFactor = 0.5;
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
//
|
||||||
|
void OnTick() {
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Ask and Bid Price values ...
|
||||||
|
double ask = ...
|
||||||
|
double bid = ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// here we loop through all open Positions ...
|
||||||
|
for (int i = PositionsTotal() - 1; i >=0; i--) {
|
||||||
|
//
|
||||||
|
// retrieve position ticket ...
|
||||||
|
ulong positionTicket = PositionGetTicket(i);
|
||||||
|
|
||||||
|
//
|
||||||
|
// retrieve Position by it's Ticket ...
|
||||||
|
if (PositionSelectByTicket(positionTicket)) {
|
||||||
|
//
|
||||||
|
// now we can check conditions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Position Open Price ...
|
||||||
|
double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Position Volume ...
|
||||||
|
double positionVolume = PositionGetDouble(POSITION_VOLUME);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Position Type: Buy or Sell Position ...
|
||||||
|
ENUM_POSITION_TYPE positionType = (ENUM_POSITION_TYPE) PositionGetInteger(POSITION_TYPE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// now we have check position volume, for prevent partialy closing a partial closed position ...
|
||||||
|
if (positionVolume == Lots) {
|
||||||
|
//
|
||||||
|
// Calculate Partially close volume ...
|
||||||
|
double lotsToClose = positionVolume * PartialCloseFactor;
|
||||||
|
lotsToClose = NormalizeDouble(lotsToClose, 2);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Position Type and do Partial Close based on Separation Type ...
|
||||||
|
if (positionType == POSITION_TYPE_BUY) {
|
||||||
|
//
|
||||||
|
// Partialy Close Buy Positions ...
|
||||||
|
if (bid > positionOpenPrice + PartialClosePoints * _Point) {
|
||||||
|
//
|
||||||
|
// Try to Partially Close Position ...
|
||||||
|
if (trade.PositionClosePartial(positionTicket, lotsToClose)) {
|
||||||
|
//
|
||||||
|
// show a simple message ...
|
||||||
|
Print("Pos ", positionTicket, " was closed partially ...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (positionType == POSITION_TYPE_SELL) {
|
||||||
|
//
|
||||||
|
// Partialy Close Sell Positions ...
|
||||||
|
if (ask < positionOpenPrice - PartialClosePoints * _Point) {
|
||||||
|
//
|
||||||
|
// Try to Partially Close Position ...
|
||||||
|
if (trade.PositionClosePartial(positionTicket, lotsToClose)) {
|
||||||
|
//
|
||||||
|
// show a simple message ...
|
||||||
|
Print("Pos ", positionTicket, " was closed partially ...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## add a Break Event Stop
|
||||||
|
|
||||||
|
some times is some trades we need to make a position risk free.
|
||||||
|
this means when a position triggered at specified point of profits, move sl to specified point.
|
||||||
|
|
||||||
|
for example we have a buy position of 100.100 price.
|
||||||
|
we need to move it's sl when bid price touch 100.150 to 100.105
|
||||||
|
|
||||||
|
moving sl of a position called Break Event ...
|
||||||
|
|
||||||
|
for this reason we have to specify 2 pqarams:
|
||||||
|
|
||||||
|
- TriggerPoint: this is a value which we change sl of position when or open price of position changed by this point;
|
||||||
|
- PufferPoint: this is a value which we change sl based on it.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
void OnTick() {
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
//
|
||||||
|
// here we loop through all open Positions ...
|
||||||
|
for (int i = PositionsTotal() - 1; i >=0; i--) {
|
||||||
|
//
|
||||||
|
// retrieve position ticket ...
|
||||||
|
ulong positionTicket = PositionGetTicket(i);
|
||||||
|
|
||||||
|
//
|
||||||
|
// retrieve Position by it's Ticket ...
|
||||||
|
if (PositionSelectByTicket(positionTicket)) {
|
||||||
|
//
|
||||||
|
// now we can check conditions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Position Open Price ...
|
||||||
|
double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Position TP ...
|
||||||
|
double positionTP = PositionGetDouble(POSITION_TP);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Position SL ...
|
||||||
|
double positionSL = PositionGetDouble(POSITION_SL);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Position Volume ...
|
||||||
|
double positionVolume = PositionGetDouble(POSITION_VOLUME);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Position Type: Buy or Sell Position ...
|
||||||
|
ENUM_POSITION_TYPE positionType = (ENUM_POSITION_TYPE) PositionGetInteger(POSITION_TYPE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Position Type and do Partial Close based on Separation Type ...
|
||||||
|
if (positionType == POSITION_TYPE_BUY) {
|
||||||
|
//
|
||||||
|
// Break Event Buy Positions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check if Price recive to value for changing sl ...
|
||||||
|
if (bid > positionOpenPrice + BETriggerPoint * _Point) {
|
||||||
|
//
|
||||||
|
// Calculate new SL Price ...
|
||||||
|
double sl = positionOpenPrice + BEPufferPoint * _Points;
|
||||||
|
sl = NormalizeDouble(sl, _Digits);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check new Calculated SL be Bigger than current SL ...
|
||||||
|
if (sl > positionSL) {
|
||||||
|
//
|
||||||
|
// Modify Trade and Change it's SL ...
|
||||||
|
if (trader.PositionModify(positionTicket, sl, positionTp)) {
|
||||||
|
//
|
||||||
|
Print("Pos ", poistionTicket, " was saved as Break Event ...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (positionType == POSITION_TYPE_SELL) {
|
||||||
|
//
|
||||||
|
// Break Event Sell Positions ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check if Price recive to value for changing sl ...
|
||||||
|
if (ask < positionOpenPrice - BETriggerPoint * _Point) {
|
||||||
|
//
|
||||||
|
// Calculate new SL Price ...
|
||||||
|
double sl = positionOpenPrice - BEPufferPoint * _Points;
|
||||||
|
sl = NormalizeDouble(sl, _Digits);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check new Calculated SL be Bigger than current SL ...
|
||||||
|
if (sl < positionSL) {
|
||||||
|
//
|
||||||
|
// Modify Trade and Change it's SL ...
|
||||||
|
if (trader.PositionModify(positionTicket, sl, positionTp)) {
|
||||||
|
//
|
||||||
|
Print("Pos ", poistionTicket, " was saved as Break Event ...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Backtesting
|
||||||
|
|
||||||
|
you must use Strategy tester in back test ...
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Candle Indexing
|
||||||
|
|
||||||
|
like Pine Script, in MQL 4 or 5 Candles, Buffers and Series indexed in reversal pattern.
|
||||||
|
this is an important note ...
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
# Chart Indicator Tutorial
|
||||||
|
|
||||||
|
## Create Indicator
|
||||||
|
|
||||||
|
open meta editor and create a new custom indicator.
|
||||||
|
|
||||||
|
## Inputs
|
||||||
|
|
||||||
|
we have to show 2 lines in chart as my indicator, so in creation time, i specified these on input window:
|
||||||
|
|
||||||
|
line 1 => Line => Red
|
||||||
|
line 2 => Line => Yellow
|
||||||
|
|
||||||
|
in this section if you check the Indicator in separate window, you tell the MT4 which this is an Oscillator.
|
||||||
|
|
||||||
|
after finish this section and source code will opened in meta editor.
|
||||||
|
you can see how it defined as source code ...
|
||||||
|
|
||||||
|
i will complete all next works on the source code, and comment it ...
|
||||||
|
|
||||||
|
## Source Code
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// these line are comment lines and no necessary ...
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| x-saherelm-custom-indicator.mq4 |
|
||||||
|
//| Copyright 2023, SaherElm IT Center. |
|
||||||
|
//| https://www.saherelm.ir |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
|
||||||
|
//
|
||||||
|
// all compiler options defines using # sign ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// here define some global properties of indicator ...
|
||||||
|
// these are not necessary, but provides some usefull info about indicator itself ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center."
|
||||||
|
#property link "https://www.saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
|
||||||
|
//
|
||||||
|
// use for improvement compiling ...
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// here we tell this is usually indicator which
|
||||||
|
// represent's on chart itself ...
|
||||||
|
#property indicator_chart_window
|
||||||
|
|
||||||
|
//
|
||||||
|
// define which buffers processed using this indicator ...
|
||||||
|
#property indicator_buffers 2
|
||||||
|
|
||||||
|
//
|
||||||
|
// define which plots represent using this indicator ...
|
||||||
|
#property indicator_plots 2
|
||||||
|
|
||||||
|
//
|
||||||
|
// here we declare plot line1 to system ...
|
||||||
|
#property indicator_label1 "line1"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrLime
|
||||||
|
#property indicator_style1 STYLE_SOLID
|
||||||
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// here we declare plot line2 to system ...
|
||||||
|
#property indicator_label2 "line2"
|
||||||
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_color2 clrRed
|
||||||
|
#property indicator_style2 STYLE_SOLID
|
||||||
|
#property indicator_width2 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// here we declare indicator buffers ...
|
||||||
|
double line1Buffer[];
|
||||||
|
double line2Buffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Custom indicator initialization function |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
|
||||||
|
//
|
||||||
|
// this event handle used to initialize what we want to use and what we
|
||||||
|
// can do on indicator ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// indicator buffers mapping ...
|
||||||
|
// we must assign which buffer must used to drawn which plot ...
|
||||||
|
SetIndexBuffer(0,line1Buffer);
|
||||||
|
SetIndexBuffer(1,line2Buffer);
|
||||||
|
|
||||||
|
//
|
||||||
|
// this means initialization end's successfully ...
|
||||||
|
return(INIT_SUCCEEDED);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
//| Custom indicator iteration function |
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
|
||||||
|
//
|
||||||
|
// this event handler calls with system every time a change happens on price ( new tick ) ...
|
||||||
|
// all of calculatings must be done in this section ...
|
||||||
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated,
|
||||||
|
const datetime &time[],
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &low[],
|
||||||
|
const double &close[],
|
||||||
|
const long &tick_volume[],
|
||||||
|
const long &volume[],
|
||||||
|
const int &spread[]
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// here we must do all of indicator related calculations and fill buffers for drawing plots on chart ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// return value of prev_calculated for next call
|
||||||
|
return(rates_total);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
```
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# ChartRedraw
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//--- redraw the chart and wait for 1 second
|
||||||
|
ChartRedraw();
|
||||||
|
```
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Comment
|
||||||
|
|
||||||
|
by this command you can show som data on charts window itself.
|
||||||
|
this data can be change through candles.
|
||||||
|
|
||||||
@@ -0,0 +1,203 @@
|
|||||||
|
# DrawFibonnaci
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// START Draw Fibonachi Retracement Object ...
|
||||||
|
//
|
||||||
|
// //
|
||||||
|
// int fibIndex = 0;
|
||||||
|
// int fibLevelsCount = 6;
|
||||||
|
// int fibLevelWidths[6];
|
||||||
|
// color fibLevelColors[6];
|
||||||
|
// double fibLevelValues[6];
|
||||||
|
// string fibLevelDescriptions[6];
|
||||||
|
// ENUM_LINE_STYLE fibLevelStyles[6];
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Level 1 ...
|
||||||
|
// // 0.0
|
||||||
|
// // clrGray ...
|
||||||
|
// fibLevelValues[fibIndex] = 0.0;
|
||||||
|
// fibLevelColors[fibIndex] = clrGray;
|
||||||
|
// fibLevelStyles[fibIndex] = STYLE_DOT;
|
||||||
|
// fibLevelWidths[fibIndex] = 1;
|
||||||
|
// fibLevelDescriptions[fibIndex] = "0.0 @ %$";
|
||||||
|
// fibIndex++;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Level 2 ...
|
||||||
|
// // 0.236
|
||||||
|
// // clrOliveDrab ...
|
||||||
|
// fibLevelValues[fibIndex] = 0.236;
|
||||||
|
// fibLevelColors[fibIndex] = clrOliveDrab;
|
||||||
|
// fibLevelStyles[fibIndex] = STYLE_DOT;
|
||||||
|
// fibLevelWidths[fibIndex] = 1;
|
||||||
|
// fibLevelDescriptions[fibIndex] = "0.236 @ %$";
|
||||||
|
// fibIndex++;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Level 3 ...
|
||||||
|
// // 0.382
|
||||||
|
// // clrYellow ...
|
||||||
|
// fibLevelValues[fibIndex] = 0.382;
|
||||||
|
// fibLevelColors[fibIndex] = clrYellow;
|
||||||
|
// fibLevelStyles[fibIndex] = STYLE_DASHDOTDOT;
|
||||||
|
// fibLevelWidths[fibIndex] = 1;
|
||||||
|
// fibLevelDescriptions[fibIndex] = "0.382 @ %$";
|
||||||
|
// fibIndex++;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Level 4 ...
|
||||||
|
// // 0.5
|
||||||
|
// // clrLime ...
|
||||||
|
// fibLevelValues[fibIndex] = 0.5;
|
||||||
|
// fibLevelColors[fibIndex] = clrLime;
|
||||||
|
// fibLevelStyles[fibIndex] = STYLE_DASHDOT;
|
||||||
|
// fibLevelWidths[fibIndex] = 1;
|
||||||
|
// fibLevelDescriptions[fibIndex] = "0.5 @ %$";
|
||||||
|
// fibIndex++;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Level 5 ...
|
||||||
|
// // 0.618
|
||||||
|
// // clrYellow ...
|
||||||
|
// fibLevelValues[fibIndex] = 0.618;
|
||||||
|
// fibLevelColors[fibIndex] = clrYellow;
|
||||||
|
// fibLevelStyles[fibIndex] = STYLE_DASHDOTDOT;
|
||||||
|
// fibLevelWidths[fibIndex] = 1;
|
||||||
|
// fibLevelDescriptions[fibIndex] = "0.618 @ %$";
|
||||||
|
// fibIndex++;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Level 6 ...
|
||||||
|
// // 1
|
||||||
|
// // clrGray ...
|
||||||
|
// fibLevelValues[fibIndex] = 1.0;
|
||||||
|
// fibLevelColors[fibIndex] = clrGray;
|
||||||
|
// fibLevelStyles[fibIndex] = STYLE_DOT;
|
||||||
|
// fibLevelWidths[fibIndex] = 1;
|
||||||
|
// fibLevelDescriptions[fibIndex] = "1.0 @ %$";
|
||||||
|
// fibIndex++;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// string fibName = StringConcatenate(
|
||||||
|
// signalPrefix,
|
||||||
|
// "_[", totalSignals, "]_",
|
||||||
|
// "[Fibo]"
|
||||||
|
// );
|
||||||
|
|
||||||
|
// //
|
||||||
|
// double fibDestPrice = hasLongSignal ?
|
||||||
|
// slInfo.longSL :
|
||||||
|
// slInfo.shortSL;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // Draw Fibonacci on Signal Propposed Area ...
|
||||||
|
// DrawCustomFibonacci(
|
||||||
|
// fibLevelsCount,
|
||||||
|
// fibLevelValues,
|
||||||
|
// fibLevelColors,
|
||||||
|
// fibLevelStyles,
|
||||||
|
// fibLevelWidths,
|
||||||
|
// fibLevelDescriptions,
|
||||||
|
// 0, // Chart ID ...
|
||||||
|
// fibName, // Object Name ...
|
||||||
|
// 0, // SubWindow ...
|
||||||
|
// zigZagHighTime, // Time 1 ...
|
||||||
|
// zigZagHigh, // Price 1 ...
|
||||||
|
// time, // Time 2 ...
|
||||||
|
// fibDestPrice, // Price 2 ...
|
||||||
|
// clrCadetBlue // Fib Aroow Color ...
|
||||||
|
// );
|
||||||
|
|
||||||
|
//
|
||||||
|
// TODO: now we have to analyse Entry Point (price), using Fib ...
|
||||||
|
// string fibLevel3Description = "";
|
||||||
|
// fibLevel3Description = ObjectGetFiboDescription(fibName, 2);
|
||||||
|
// string message = StringConcatenate(
|
||||||
|
// "Fib Level 3 Desc: ",
|
||||||
|
// fibLevel3Description
|
||||||
|
// );
|
||||||
|
// LogMessage(fibLevel3Description);
|
||||||
|
|
||||||
|
// //
|
||||||
|
// //
|
||||||
|
// string fibLevel5Description = "";
|
||||||
|
|
||||||
|
//
|
||||||
|
double fibDestPrice = hasLongSignal ?
|
||||||
|
slInfo.longSL :
|
||||||
|
slInfo.shortSL;
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime fibTime1 = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
1
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime fibTime2 = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double minFibLevelValue = 0.382;
|
||||||
|
double minFibLevel = GetFibonacciLevel(
|
||||||
|
zigZagHigh, // Up ...
|
||||||
|
fibDestPrice, // Down ...
|
||||||
|
minFibLevelValue, // Level ...
|
||||||
|
X_DOWN // Direction ...
|
||||||
|
);
|
||||||
|
string minFibLevelName = StringConcatenate(
|
||||||
|
signalPrefix,
|
||||||
|
"_[", totalSignals, "]_",
|
||||||
|
"[Fibo_0.382]"
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw minFibLevel ...
|
||||||
|
DrawTrendLine(
|
||||||
|
0,
|
||||||
|
minFibLevelName,
|
||||||
|
0,
|
||||||
|
fibTime1,
|
||||||
|
minFibLevel,
|
||||||
|
fibTime2,
|
||||||
|
minFibLevel,
|
||||||
|
clrYellow
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double maxFibLevelValue = 0.618;
|
||||||
|
double maxFibLevel = GetFibonacciLevel(
|
||||||
|
zigZagHigh, // Up ...
|
||||||
|
fibDestPrice, // Down ...
|
||||||
|
maxFibLevelValue, // Level ...
|
||||||
|
X_DOWN // Direction ...
|
||||||
|
);
|
||||||
|
string maxFibLevelName = StringConcatenate(
|
||||||
|
signalPrefix,
|
||||||
|
"_[", totalSignals, "]_",
|
||||||
|
"[Fibo_0.618]"
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw minFibLevel ...
|
||||||
|
DrawTrendLine(
|
||||||
|
0,
|
||||||
|
minFibLevelName,
|
||||||
|
0,
|
||||||
|
fibTime1,
|
||||||
|
maxFibLevel,
|
||||||
|
fibTime2,
|
||||||
|
maxFibLevel,
|
||||||
|
clrYellow
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// END Draw Fibonachi Retracement Object ...
|
||||||
|
//
|
||||||
|
```
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
# Draw Signal
|
||||||
|
|
||||||
|
```mql
|
||||||
|
//
|
||||||
|
// Draw a shape On Chart ...
|
||||||
|
if (hasLongSignal) {
|
||||||
|
//
|
||||||
|
arrowups++;
|
||||||
|
|
||||||
|
//
|
||||||
|
string arrowUpName = StringConcatenate(signalPrefix, "_ArrowUp_", arrowups);
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime arrowTime = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double arrowPrice = iOpen(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
arrowPrice = arrowPrice - (100 * _Point);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw Signal Arrow Shape ...
|
||||||
|
bool isDraw = DrawArrow(
|
||||||
|
0,
|
||||||
|
arrowUpName,
|
||||||
|
0,
|
||||||
|
arrowTime,
|
||||||
|
arrowPrice,
|
||||||
|
SYMBOL_ARROWUP,
|
||||||
|
ANCHOR_BOTTOM,
|
||||||
|
clrAqua,
|
||||||
|
STYLE_SOLID,
|
||||||
|
3,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// SL Info ...
|
||||||
|
XSLInfo slInfo = GetSwngSL(bar_index);
|
||||||
|
|
||||||
|
//
|
||||||
|
// TP Info ...
|
||||||
|
XTPInfo tpInfo = GetTP(bar_index);
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
string arrowUpSLName = StringConcatenate(signalPrefix, "_SL_", arrowups);
|
||||||
|
string arrowUpTPName = StringConcatenate(signalPrefix, "_TP_", arrowups);
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime time1 = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index + 1
|
||||||
|
);
|
||||||
|
datetime time2 = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw Signal SL ...
|
||||||
|
DrawTrendLine(
|
||||||
|
0,
|
||||||
|
arrowUpSLName,
|
||||||
|
0,
|
||||||
|
time1,
|
||||||
|
slInfo.longSL,
|
||||||
|
time2,
|
||||||
|
slInfo.longSL,
|
||||||
|
clrFuchsia,
|
||||||
|
STYLE_SOLID,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Draw Signal TP ...
|
||||||
|
DrawTrendLine(
|
||||||
|
0,
|
||||||
|
arrowUpTPName,
|
||||||
|
0,
|
||||||
|
time1,
|
||||||
|
tpInfo.longTP,
|
||||||
|
time2,
|
||||||
|
tpInfo.longTP,
|
||||||
|
clrAqua,
|
||||||
|
STYLE_SOLID,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,309 @@
|
|||||||
|
# EA Tutorials
|
||||||
|
|
||||||
|
in this tutorial we cover this titles step by step:
|
||||||
|
|
||||||
|
1. Create new Expert Advisor
|
||||||
|
2. Variables
|
||||||
|
3. Functions
|
||||||
|
4. Control Structures
|
||||||
|
5. Read Indicator Data
|
||||||
|
6. Open Trades
|
||||||
|
7. Modify Trades
|
||||||
|
8. Close Trades
|
||||||
|
|
||||||
|
## Create new Expert Advisor
|
||||||
|
|
||||||
|
in meta editor (f4, tools > meta editor), click on new and select expert adviser.
|
||||||
|
|
||||||
|
as you know all mql programs runing based on event handlers.
|
||||||
|
|
||||||
|
there are three main event handlers, which used in an EA:
|
||||||
|
|
||||||
|
- OnInit // runs each time tf changes, or ea attached ...
|
||||||
|
- OnDeinit // runs when ea removed from chart ...
|
||||||
|
- OnTick // most important function, all of business logics implemented here ...
|
||||||
|
|
||||||
|
you can see all of it's documents on proppered file.
|
||||||
|
|
||||||
|
the main feature of an EA in MQL, is there are some features which helps us. such as notification of signals and auto trading abbility.
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
usually used to store some values of specific Data Types.
|
||||||
|
so this is much better to see supported datat types in documentations.
|
||||||
|
|
||||||
|
for using variables, you had to define a variable, also you can set init value of it's supported data type.
|
||||||
|
each variable must be specific it's own data type.
|
||||||
|
|
||||||
|
each variable defined by assign a name to it.
|
||||||
|
|
||||||
|
so by using this name you can assign value to it or read it assigned value ...
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
in programming, a function can get some params and do some actions on them and return a result.
|
||||||
|
doing some actions is the permanent part of it's definition.
|
||||||
|
this means a function can only do a simple action and not have any params, and not have any return type.
|
||||||
|
|
||||||
|
each function must contain a unioque name.
|
||||||
|
|
||||||
|
in scope of project you can call a function by providing it's name and passing required params and also gives it's result.
|
||||||
|
|
||||||
|
## Control Structures
|
||||||
|
|
||||||
|
conditional operators gives an expression and determines it's result is true or false.
|
||||||
|
there are many commands in programming which used a conditional expression to act based on it's result.
|
||||||
|
by this way you can make your own business logic to control programming flow, or data flow or anything you want.
|
||||||
|
|
||||||
|
most commonly used conditional command is if command, which used like this syntax:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
if (conditional_expression) {
|
||||||
|
//
|
||||||
|
// Blocks of code which run when conditional expression is true ...
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
// Blocks of code which run when conditional expression is false ...
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
also we can make loops in programing, a loop is a code blocks which runs until a condition happens.
|
||||||
|
there are many type of loops in programming languages.
|
||||||
|
|
||||||
|
most commonly used loops is create using for command by following this syntax:
|
||||||
|
|
||||||
|
for (int i; i <= 6; i++) {
|
||||||
|
//
|
||||||
|
// Loop Code Block ...
|
||||||
|
Print("Loop Itrator: ", i);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Read Indicator Data
|
||||||
|
|
||||||
|
in this example we specially use RSI indicator.
|
||||||
|
but you can replace this by any other indicator you want, strusture is same;
|
||||||
|
|
||||||
|
RSI Indicator provide a value for each candle and draw a line. this value is between 0 and 100;
|
||||||
|
|
||||||
|
**Note** each standard indicator in MQL has a related function, which is usually starts with i{IndicatorName}, such as iRSI, iIchimoku and etc.
|
||||||
|
this functions, return specific values related to Indicator Data.
|
||||||
|
by calling this functions you can capture Indicator data for specific types of inputs.
|
||||||
|
|
||||||
|
there are some standard inputs which usually used as params in iFunctions which i describe them in following:
|
||||||
|
|
||||||
|
- Symbol: reffer to which symbol you need to inject it's data from indicator. (_Symbol)
|
||||||
|
- Period: reffer to which Time Frame you need to inject symbol's data on it from indicator (CURRENT_PERIOD).
|
||||||
|
- ...
|
||||||
|
|
||||||
|
as i described before all candle related data, or indicators data, usually stores in Buffers.
|
||||||
|
by calling iFunctions, you retrieve an integer result, which it's an index number that point to a Buffer.
|
||||||
|
for using it's value, you had to create a Buffer on top of it.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// here we define a pointer to iFunction buffer ...
|
||||||
|
// for reading values, each time we need we had to define
|
||||||
|
// a global pointer and then fill it on Init handler ...
|
||||||
|
int rsiPointer = iRSI(_Symbol, _Period, 14, PRICE_CLOSE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// define a dynamic size array, which calls Buffer ...
|
||||||
|
double rsiBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// fill defined Buffer by iFunction Pointer ...
|
||||||
|
CopyBuffer(rsiPointer, 0, 1, 1, s);
|
||||||
|
```
|
||||||
|
|
||||||
|
**Note** there are some different ways in MQL4 and MQL5 to read the Pointer value. as i think this above described method is for MQL5, since in MQL4 for each bar_index, you shoud to call the iFunction once, by passing the bar to it ...
|
||||||
|
|
||||||
|
## Open Trades
|
||||||
|
|
||||||
|
as i described before, one of the main features an EA Programs, which used commonly is to Open Trade positions and specific conditions.
|
||||||
|
|
||||||
|
imagine that we want to send signal for Long and Short positions, based on rsi value.
|
||||||
|
the condition is when rsi value at the current candle is abopve than 70, means Bullish Signal, and otherwise if it is below than 30 means Bearish Signal.
|
||||||
|
|
||||||
|
we can handle this in OnTick event handler like this:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Prepare RSI Buffer ...
|
||||||
|
double rsi[];
|
||||||
|
CopyBuffer(rsiPointer, 0, 1, 1, rsi);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Prepare Signal Conditions ...
|
||||||
|
if (rsi[0] > 70) {
|
||||||
|
//
|
||||||
|
// Bullish Signal ...
|
||||||
|
} else if (rsi[0] < 30) {
|
||||||
|
//
|
||||||
|
// Bearish Signal ...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
we need to open position based on above Trading Conditions.
|
||||||
|
|
||||||
|
at the first step we have to include Trade library in our EA Project.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// here we include header file ...
|
||||||
|
#include <Trade/Trade.mqh>
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
|
//
|
||||||
|
// now we have to define an instance of CTrade class to manipulate Positions ...
|
||||||
|
CTrade trader;
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
after create CTrade instance, we have to use it in right way and right place to manipulate positions:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Prepare Signal Conditions ...
|
||||||
|
if (rsi[0] > 70) {
|
||||||
|
//
|
||||||
|
// Bearish Signal ...
|
||||||
|
trader.Sell(0.001, _Symbol);
|
||||||
|
} else if (rsi[0] < 30) {
|
||||||
|
//
|
||||||
|
// Bullish Signal ...
|
||||||
|
trader.Buy(0.01. _Symbol);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
in above example, we just open positions and there is no access to them for manipulate them.
|
||||||
|
we have to specify unique id to each position and store them somewhere in our EA to next times we have to manage or manipulate positions, simply reffer to them ...
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Prepare Signal Conditions ...
|
||||||
|
if (rsi[0] > 70) {
|
||||||
|
//
|
||||||
|
// Bearish Signal ...
|
||||||
|
trader.Sell(0.001, _Symbol);
|
||||||
|
ulong ticket = trader.ResultOrder();
|
||||||
|
} else if (rsi[0] < 30) {
|
||||||
|
//
|
||||||
|
// Bullish Signal ...
|
||||||
|
// we can provide tp and sl on positions ...
|
||||||
|
trader.Buy(0.01. _Symbol);
|
||||||
|
ulong ticket = trader.ResultOrder();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
we can simply check ticket as a global variable and then before opening new position, check it's value and then provide business logic ...
|
||||||
|
|
||||||
|
## Modify Trades
|
||||||
|
|
||||||
|
before do any manipulation on a position, we have to select the position itself ...
|
||||||
|
|
||||||
|
PositionSelectByTicket is a Method which used to select a position by providing it's ticket id.
|
||||||
|
this returns a boolean value which determines position selected correctly or not ...
|
||||||
|
|
||||||
|
[here](https://www.mql5.com/en/docs/constants/tradingconstants/positionproperties) are some resources related to position.
|
||||||
|
|
||||||
|
for modifying an specific position, we have to use this function like following:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// assume that this value filled on opening a position ...
|
||||||
|
ulong positionTicket;
|
||||||
|
|
||||||
|
//
|
||||||
|
// validate position selectedsuccessfully, then try
|
||||||
|
// to manipulate it ...
|
||||||
|
if (PositionSelectByTicket(positionTicket)) {
|
||||||
|
//
|
||||||
|
// Do what ever we want to modify on popsition ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// reading some Position info ...
|
||||||
|
double positionPrice = PositionGetDouble(POSITION_PRICE_OPEN);
|
||||||
|
double positionTP = PositionGetDouble(POSITION_TP);
|
||||||
|
double positionSL = PositionGetDouble(POSITION_SL);
|
||||||
|
|
||||||
|
//
|
||||||
|
// detect Position Type ...
|
||||||
|
// POSITION_TYPE_BUY
|
||||||
|
// POSITION_TYPE_SELL
|
||||||
|
int positionType = PositionGetInteger(POSITION_TYPE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check Position has SL ...
|
||||||
|
if (positionSL == 0) {
|
||||||
|
//
|
||||||
|
// here we calculate and define SL and TP for position ...
|
||||||
|
double sl = 0;
|
||||||
|
double tp = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// then we use PositionModify method to apply our changes on specified Position ...
|
||||||
|
trader.PositionModify(positionTicket, sl, tp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Close Trades
|
||||||
|
|
||||||
|
some times we need to conditionally close an open position. maybe some times we got a reversal signal or anything else, based on our EA Business Logic.
|
||||||
|
for this we can also check positionTicket must be greater than zero.
|
||||||
|
|
||||||
|
in following code, we update above sample to add supports for close last open position, before opening another one ...
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Prepare Signal Conditions ...
|
||||||
|
if (rsi[0] > 70) {
|
||||||
|
//
|
||||||
|
// close last open position ...
|
||||||
|
// this condition means there are an open position ...
|
||||||
|
if (positionTicket > 0 && PositionSelectByTicket(positionTicket)) {
|
||||||
|
//
|
||||||
|
// retrieve Position Type ...
|
||||||
|
int positionType = PositionGetInteger(POSITION_TYPE);
|
||||||
|
if (positionType == POSITION_TYPE_BUY) {
|
||||||
|
//
|
||||||
|
// Close Position ...
|
||||||
|
trade.PositionClose(positionTicket);
|
||||||
|
|
||||||
|
//
|
||||||
|
positionTicket = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Bearish Signal ...
|
||||||
|
trader.Sell(0.001, _Symbol);
|
||||||
|
positionTicket = trader.ResultOrder();
|
||||||
|
} else if (rsi[0] < 30) {
|
||||||
|
//
|
||||||
|
// close last open position ...
|
||||||
|
// this condition means there are an open position ...
|
||||||
|
if (positionTicket > 0 && PositionSelectByTicket(positionTicket)) {
|
||||||
|
//
|
||||||
|
// retrieve Position Type ...
|
||||||
|
int positionType = PositionGetInteger(POSITION_TYPE);
|
||||||
|
if (positionType == POSITION_TYPE_SELL) {
|
||||||
|
//
|
||||||
|
// Close Position ...
|
||||||
|
trade.PositionClose(positionTicket);
|
||||||
|
|
||||||
|
//
|
||||||
|
positionTicket = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Bullish Signal ...
|
||||||
|
// we can provide tp and sl on positions ...
|
||||||
|
trader.Buy(0.01. _Symbol);
|
||||||
|
positionTicket = trader.ResultOrder();
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Expert Adviser
|
||||||
|
|
||||||
|
a complete combination of all of features in meta trader to calculate anything in business logic and draw wath we want on chart. even mopre, advice some position related data to user.
|
||||||
|
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
# Get Account Balance
|
||||||
|
|
||||||
|
[Resource](https://docs.mql4.com/account/accountinfodouble)
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Retrieve Account Balance ...
|
||||||
|
double Balance = AccountInfoDouble(ACCOUNT_BALANCE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Account Equity ...
|
||||||
|
double Equity = AccountInfoDouble(ACCOUNT_EQUITY);
|
||||||
|
```
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Get Bid Price
|
||||||
|
|
||||||
|
bid price means our buy price.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID, _Digits));
|
||||||
|
```
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# Input
|
||||||
|
|
||||||
|
Input Variables
|
||||||
|
The input storage class defines the external variable. The input modifier is indicated before the data type. A variable with the input modifier can't be changed inside mql4-programs, such variables can be accessed for reading only. Values of input variables can be changed only by a user from the program properties window. External variables are always reinitialized immediately before the OnInit() is called.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
//--- input parameters
|
||||||
|
input int MA_Period=13;
|
||||||
|
input int MA_Shift=0;
|
||||||
|
input ENUM_MA_METHOD MA_Method=MODE_SMMA;
|
||||||
|
|
||||||
|
There is another way to set how your input parameter will look like in the Inputs tab. For this, place a string comment after the description of an input parameter in the same line. In this way you can make names of input parameters more understandable for users.
|
||||||
|
|
||||||
|
//--- input parameters
|
||||||
|
input int InpMAPeriod=13; // Smoothing period
|
||||||
|
input int InpMAShift=0; // Line horizontal shift
|
||||||
|
input ENUM_MA_METHOD InpMAMethod=MODE_SMMA; // Smoothing method
|
||||||
|
|
||||||
|
input ENUM_MA_METHOD MAMethod = MODE_EMA;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Gives time frame as an input ...
|
||||||
|
input ENUM_TIMEFRAMES Timeframe = PERIOD_CURRENT;
|
||||||
|
|
||||||
|
|
||||||
|
in adding input data to your advisors, indicators or etc, you can groups your input's together.
|
||||||
|
for this following below descriptions:
|
||||||
|
|
||||||
|
int group "Moving Avarage Filter"
|
||||||
|
|
||||||
|
every inputs appears after this, attached to created group ...
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
# IsNewBar
|
||||||
|
|
||||||
|
this is a best way to find is in new bar or not ...
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
bool IsNewBar()
|
||||||
|
{
|
||||||
|
static datetime lastbar;
|
||||||
|
datetime curbar = (datetime)SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE);
|
||||||
|
if(lastbar != curbar)
|
||||||
|
{
|
||||||
|
lastbar = curbar;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Libraries
|
||||||
|
|
||||||
|
in programming there is concept which named Library, Module, Package or etc, and this concept is a place which consist of some classes and grouped functions.
|
||||||
|
this package and compiled and other programmers can only used this packages provided tools and stuffs regarding less to access it's source code. it is a BlackBox.
|
||||||
|
|
||||||
|
in MQL Libraries compiled to files by .mqh extension, like C++, and can imports using include reserved key.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#include <Trade/Trade.mqh>
|
||||||
|
```
|
||||||
|
|
||||||
|
see Include file ...
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
# MQL
|
||||||
|
|
||||||
|
MetaQuotes Language 4 (MQL4) is a built-in language for programming trading strategies. This language is developed by MetaQuotes Software Corp. based on their long experience in the creation of online trading platforms. Using this language, you can create your own Expert Advisors that make trading management automated and are perfectly suitable for implementing your own trading strategies. Besides, using MQL4 you can create your own technical indicators (custom indicators), scripts and libraries.
|
||||||
|
|
||||||
|
[Resource](https://docs.mql4.com/)
|
||||||
|
|
||||||
|
Programs written in MetaQuotes Language 4 have different features and purposes:
|
||||||
|
|
||||||
|
Expert Advisor is a mechanical trading system linked up to a certain chart. An Expert Advisor starts to run when an event happens that can be handled by it: events of initialization and deinitialization, event of a new tick receipt, a timer event, depth of market changing event, chart event and custom events.
|
||||||
|
An Expert Advisor can both inform you about a possibility to trade and automatically trade on an account sending orders directly to a trade server. Expert Advisors are stored in terminal_directory\MQL4\Experts.
|
||||||
|
Custom Indicator is a technical indicator written independently in addition to those already integrated into the client terminal. Like built-in indicators, they cannot trade automatically and are intended for implementing of analytical functions only.
|
||||||
|
Custom indicators are stored in terminal_directory\MQL4\Indicators
|
||||||
|
Script is a program intended for a single execution of some actions. Unlike Expert Advisors, scripts do not process any actions, except for the start event (this requires the OnStart handler function in a script). Scripts are stored in terminal_directory\MQL4\Scripts
|
||||||
|
Library is a set of custom functions intended for storing and distributing frequently used blocks of custom programs. Libraries cannot start executing by themselves.
|
||||||
|
Libraries are stored in terminal_directory\MQL4\Libraries
|
||||||
|
Include File is a source text of the most frequently used blocks of custom programs. Such files can be included into the source texts of Expert Advisors, scripts, custom indicators, and libraries at the compiling stage. The use of included files is more preferable than the use of libraries because of additional burden occurring at calling library functions.
|
||||||
|
Include files can be stored in the same directory as a source file - in this case the #include directive with double quotes is used. Another place to store include files is terminal_directory\MQL4\Include, in this case the #include directive is used with angle brackets.
|
||||||
|
|
||||||
|
## Language Basics
|
||||||
|
|
||||||
|
The MetaQuotes Language 4 (MQL4) is an object-oriented high-level programming language intended for writing automated trading strategies, custom technical indicators for the analysis of various financial markets. It allows not only to write a variety of expert systems, designed to operate in real time, but also create their own graphical tools to help you make trade decisions.
|
||||||
|
|
||||||
|
MQL4 is based on the concept of the popular programming language C++. The language has enumerations, structures, classes and event handling. By increasing the number of embedded main types, the interaction of executable programs in MQL4 with other applications through dll is now as easy as possible. MQL4 syntax is similar to the syntax of C++, and this makes it easy to translate into it programs from modern programming languages.
|
||||||
|
|
||||||
|
## Constants, Enumerations and Structures
|
||||||
|
|
||||||
|
[Resource](https://docs.mql4.com/constants)
|
||||||
|
|
||||||
|
To simplify the program writing and to make program texts more convenient for perception, the MQL4 language provides predefined standard constants and enumerations. Besides that, service structures are used for storing information.
|
||||||
|
|
||||||
|
Standard constants are similar to macros and are of int type.
|
||||||
|
|
||||||
|
The constants are grouped by their purposes:
|
||||||
|
|
||||||
|
- [Chart constants](https://docs.mql4.com/constants/chartconstants): are used when working with price charts: opening, navigation, setting parameters;
|
||||||
|
- [Objects constants](https://docs.mql4.com/constants/objectconstants): are intended for processing graphical objects that can be created and displayed in charts;
|
||||||
|
- [Indicators constants](https://docs.mql4.com/constants/indicatorconstants): are used for working with standard and custom indicators;
|
||||||
|
- [Environment state](https://docs.mql4.com/constants/environment_state): constants describe properties of a MQL4-program, show information about a client terminal, financial instrument and current account;
|
||||||
|
- [Trade constants](https://docs.mql4.com/constants/tradingconstants): allow to specify a variety of information in the course of trading;
|
||||||
|
- [Named constants](https://docs.mql4.com/constants/namedconstants): are constants of the MQL4 language;
|
||||||
|
- [Data structures](https://docs.mql4.com/constants/structures): describe data storage formats used;
|
||||||
|
- [Codes of errors and warnings](https://docs.mql4.com/constants/errorswarnings): describe compiler messages and trading server answers to trade requests;
|
||||||
|
- [In/out constants](https://docs.mql4.com/constants/io_constants): are designed for working with file functions and displaying messages on the screen by the MessageBox() function.
|
||||||
|
|
||||||
|
## MQL4 Programs
|
||||||
|
|
||||||
|
For the mql4-program to operate, it must be compiled (Compile button or F7 key). Compilation should pass without errors (some warnings are possible; they should be analyzed). At this process, an executable file with the same name and with EX4 extension must be created in the corresponding directory, terminal_dir\MQL4\Experts, terminal_dir\MQL4\indicators or terminal_dir\MQL4\scripts. This file can be run.
|
||||||
|
|
||||||
|
Operating features of MQL4 programs are described in the following sections:
|
||||||
|
|
||||||
|
- [Program running](https://docs.mql4.com/runtime/running): order of calling predefined event-handlers.
|
||||||
|
- [Client terminal events](https://docs.mql4.com/runtime/event_fire): description of events, which can be processed in programs.
|
||||||
|
- [Call of imported functions](https://docs.mql4.com/runtime/imports): description order, allowed parameters, search details and call agreement for imported functions.
|
||||||
|
- [Runtime errors](https://docs.mql4.com/runtime/errors): getting information about runtime and critical errors.
|
||||||
|
|
||||||
|
Expert Advisors, custom indicators and scripts are attached to one of opened charts by Drag'n'Drop method from the Navigator window.
|
||||||
|
|
||||||
|
For an expert Advisor to stop operating, it should be removed from a chart. To do it select "Expert list" in chart context menu, then select an Expert Advisor from list and click "Remove" button. Operation of Expert Advisors is also affected by the state of the "AutoTrading" button.
|
||||||
|
|
||||||
|
In order to stop a custom indicator, it should be removed from a chart.
|
||||||
|
|
||||||
|
Custom indicators and Expert Advisors work until they are explicitly removed from a chart; information about attached Expert Advisors and Indicators is saved between client terminal sessions.
|
||||||
|
|
||||||
|
Scripts are executed once and are deleted automatically upon operation completion or change of the current chart state, or upon client terminal shutdown. After the restart of the client terminal scripts are not started, because the information about them is not saved.
|
||||||
|
|
||||||
|
Maximum one Expert Advisor, one script and unlimited number of indicators can operate in one chart.
|
||||||
|
|
||||||
|
## How MQL Programs Run
|
||||||
|
|
||||||
|
[Resource](https://docs.mql4.com/runtime/running)
|
||||||
|
|
||||||
|
Right after a program is attached to a chart, it is uploaded to the client terminal memory, as well as global variable are initialized. If some global variable of the class type has a constructor, this constructor will be called during initialization of global variables.
|
||||||
|
|
||||||
|
After that the program is waiting for an event from the client terminal. Each mql4-program should have at least one event-handler, otherwise the loaded program will not be executed. Event handlers have predefined names, parameters and return types.
|
||||||
|
|
||||||
|
| Type | Function Name | Params | App Type | Comment |
|
||||||
|
| :-: | :-: | :-: | :-: | :-: |
|
||||||
|
int | [OnInit](https://docs.mql4.com/basis/function/events#oninit) | none | Expert Advisors, indicators and scripts | [Init](https://docs.mql4.com/runtime/event_fire#init) event handler. It allows to use the void return type. |
|
||||||
|
void | [OnDeinit](https://docs.mql4.com/basis/function/events#ondeinit) | const int reason | Expert Advisors, indicators and scripts | [Deinit](https://docs.mql4.com/runtime/event_fire#deinit) event handler. |
|
||||||
|
void | [OnStart](https://docs.mql4.com/basis/function/events#onstart) | none | scripts | [Start](https://docs.mql4.com/runtime/event_fire#start) event handler.
|
||||||
|
int | [OnCalculate](https://docs.mql4.com/basis/function/events#oncalculate) | const int rates_total,const int prev_calculated,const datetime &Time[],const double &Open[],const double &High[],const double &Low[],const double &Close[],const long &TickVolume[],const long &Volume[],const int &Spread[] | indicators | Calculate event handler for all prices. |
|
||||||
|
void | [OnTick](https://docs.mql4.com/basis/function/events#ontick) | none | Expert Advisors | [NewTick](https://docs.mql4.com/runtime/event_fire#newtick) event handler. While the event of a new tick receipt is being processed, no other events of this type are received. |
|
||||||
|
void | [OnTimer](https://docs.mql4.com/basis/function/events#ontimer) | none | Expert Advisors and indicators | [Timer](https://docs.mql4.com/runtime/event_fire#timer) event handler |
|
||||||
|
double | [OnTester](https://docs.mql4.com/basis/function/events#ontester) | none | Expert Advisors | [Tester](https://docs.mql4.com/runtime/event_fire#tester) event handler. |
|
||||||
|
void | [OnChartEvent](https://docs.mql4.com/basis/function/events#onchartevent) | const int id,const long &lparam,const double &dparam,const string &sparam | Expert Advisors and indicators | [ChartEvent](https://docs.mql4.com/runtime/event_fire#chartevent) event handler. |
|
||||||
|
|
||||||
|
**Libraries** do not handle any events.
|
||||||
|
|
||||||
|
## Functions prohibited in Indicators and Expert Advisors
|
||||||
|
|
||||||
|
Indicators, scripts and Expert Advisors are executable programs written in MQL4. They are designed for different types of tasks. Therefore there are some restrictions on the use of certain functions, depending on the type of program. The following functions are prohibited in indicators:
|
||||||
|
|
||||||
|
- [OrderSend()](https://docs.mql4.com/trading/ordersend);
|
||||||
|
- [SendFTP()](https://docs.mql4.com/common/sendftp);
|
||||||
|
- [Sleep()](https://docs.mql4.com/common/sleep);
|
||||||
|
- [ExpertRemove()](https://docs.mql4.com/common/expertremove);
|
||||||
|
- [MessageBox()](https://docs.mql4.com/common/messagebox).
|
||||||
|
|
||||||
|
All functions designed for indicators are prohibited in Expert Advisors and scripts:
|
||||||
|
|
||||||
|
- [SetIndexBuffer()](https://docs.mql4.com/customind/setindexbuffer);
|
||||||
|
- [IndicatorSetDouble()](https://docs.mql4.com/customind/indicatorsetdouble);
|
||||||
|
- [IndicatorSetInteger()](https://docs.mql4.com/customind/indicatorsetinteger);
|
||||||
|
- [IndicatorSetString()](https://docs.mql4.com/customind/indicatorsetstring).
|
||||||
|
|
||||||
|
The library is not an independent program and is executed in the context of the MQL4 program that has called it: script, indicator or Expert Advisor. Accordingly, the above restrictions apply to the called library.
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
# Meta Trader Strategy Tester
|
||||||
|
|
||||||
|
[Resource](https://www.mql5.com/en/blogs/post/702993)
|
||||||
|
|
||||||
|
To get the most out of your expert advisor, you'll need to optimize and backtest your strategy using MetaTrader's Strategy Tester. While forward testing on a demo account is essential, backtesting allows you to simulate trading over a long period of time in just minutes. And with the optimization feature, you can find out which settings performed best over a selected historical chart period.
|
||||||
|
|
||||||
|
There is considerable debate over the accuracy of MetaTrader's strategy tester. At best, backtesting offers only a close approximation of how trades would be executed in real-time. But it's the only tool available to rapidly test any strategy over a wide range of trading situations, and one that you should learn how to use well.
|
||||||
|
|
||||||
|
Open the Strategy Tester in MetaTrader by clicking the appropriate button on the toolbar or by selecting Strategy Tester from the View menu.
|
||||||
|
|
||||||
|
## History Center
|
||||||
|
|
||||||
|
Before backtesting or optimizing, it's important to make sure that your history data is complete and accurate, especially if you're using 'Every tick' as your testing model. If you see 'mismatched chart' errors in your Journal log or if your modeling quality is less than 90%, your history data is insufficient to generate accurate ticks.
|
||||||
|
|
||||||
|
Open the History Center from the Tools menu or by pressing F2 on your keyboard. Double click the chart pair in the left column that you plan to backtest for. A list of time periods will appear below. Start by double clicking on 1 Minute (M1) to load the history data for that period. The backtester uses M1 data to generate ticks, so it is important that your M1 data is complete.
|
||||||
|
|
||||||
|
From the History Center, you can download or import data to use in backtesting. Your broker will automatically provide some recent data, but it may not be enough for a longer backtest. In addition, the free downloadable data from MetaTrader (accessible via the Download button) is not always complete, and can contain large gaps.
|
||||||
|
|
||||||
|
You can download free M1 data from http://www.forextester.com/data/datasources.html. First, select the M1 period for the symbol from the list on the left-hand side. Click the Import button, and then click Browse in the Import dialog to select the M1 data file you just downloaded. Press OK to import the data -- it may take several minutes. You now have several years of M1 data for that symbol.
|
||||||
|
|
||||||
|
To make use of this data on higher timeframes, you'll need to use the period_converter script that comes with MetaTrader. Open a chart window and set it to M1. Drag and drop the period_converter script from the Navigator window onto the chart, and set the ExtPeriodMultiplier setting to the number of minutes to convert to. For M15, use 15; for H1, use 60; for H4, use 240, and so on.
|
||||||
|
|
||||||
|
Repeat this process for all of the symbols/periods you plan to test on. Once you have sufficient history data, you can begin testing. The video below demonstrates the process of importing and converting the M1 data:Optimization
|
||||||
|
|
||||||
|
The optimization feature of MetaTrader 4 allows you to test thousands of combinations of expert advisor settings to find the most profitable settings for the selected chart, period and date range. Indicator-based strategies will need to be optimized for maximum profitability. However, almost all EAs will benefit from optimization - even those that trade on tick data, provided you have complete M1 history data (see above).
|
||||||
|
|
||||||
|
While the optimizer will return the most profitable settings for the selected date range, this is no guarantee that these settings will be profitable in the future. Market conditions change often, so it is important to regularly re-optimize your expert advisor for best results.
|
||||||
|
|
||||||
|
To optimize your expert advisor, first select it from the Expert Advisor drop-down box. Select the currency pair from the Symbol box and chart period from the Period box. For Model, you'll generally want to select "Open Prices Only," unless you are optimizing an EA that runs on tick data. In that case, select "Every Tick." Check the Use Date option and select a range of dates to optimize for. Lastly, make sure that Optimization is checked.
|
||||||
|
|
||||||
|
Click the Expert Properties button to open your expert advisor settings. Under the Inputs tab is where you'll enter the range of values to optimize for. The Start column will be the lowest value for a given setting, while the Stop column will be the highest. The Step column is the amount that the optimizer will "step through" from the Start to the Stop setting.
|
||||||
|
|
||||||
|
## Backtesting
|
||||||
|
|
||||||
|
By now, it should be obvious how the backtester works. Select your Expert Advisor, Symbol, Period and Model, check the Use Date box and select a date range. Select Visual Mode only if you want a visual walkthrough of the backtesting. Leave Optimization unchecked.
|
||||||
|
|
||||||
|
Hit the Expert Properties button and enter your settings in the Value column under the Inputs tab. You can also load or save settings using the buttons in the bottom right. The Start, Step and Stop columns are ignored, as are the checkboxes.
|
||||||
|
|
||||||
|
Close the Expert Properties dialog and press Start to begin testing. It will take anywhere from a few seconds to several minutes depending on your settings. Once testing has finished, open the Report tab on the bottom to see your results.
|
||||||
|
|
||||||
|
A few statistics to take note of:
|
||||||
|
|
||||||
|
- **Total net profit** - The **Gross profit** minus the **Gross loss**.
|
||||||
|
- **Profit factor** - The **ratio** of **gross profit** to **gross loss**. Higher is better, anything above 1.5 is good.
|
||||||
|
- **Absolute drawdown** - The **drawdown** of your *initial deposit*. High drawdowns increase the likelihood that your account will be blown out.
|
||||||
|
- **Profit trades** - Your overall **win percentage**.
|
||||||
|
- **Modeling quality** - Only important if your testing model is **Every Tick**. If so, this should be at 90%. If not, follow the instructions above to update your history with accurate M1 data.
|
||||||
|
|
||||||
|
The Results tab at the bottom of the strategy tester will give you the details on opened and closed orders, including trailing stop, take profit and stop loss. Click the Open Chart button to get a visual representation of your results. When testing your new EA, examine these closely to ensure that your strategy is working as intended.
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# OBJPROP_CORBNER
|
||||||
|
|
||||||
|
defines the chart corner relative to which the anchor point coordinates are specified. Can be one of the 4 values of the ENUM_BASE_CORNER enumeration;
|
||||||
|
|
||||||
|
## ENUM_BASE_CORNER
|
||||||
|
|
||||||
|
- CORNER_LEFT_UPPER:
|
||||||
|
Center of coordinates is in the upper left corner of the chart.
|
||||||
|
- CORNER_LEFT_LOWER:
|
||||||
|
Center of coordinates is in the lower left corner of the chart.
|
||||||
|
- CORNER_RIGHT_LOWER:
|
||||||
|
Center of coordinates is in the lower right corner of the chart.
|
||||||
|
- CORNER_RIGHT_UPPER:
|
||||||
|
Center of coordinates is in the upper right corner of the chart.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Object Types
|
||||||
|
|
||||||
|
When a graphical object is created using the ObjectCreate() function, it's necessary to specify the type of object being created, which can be one of the values of the ENUM_OBJECT enumeration. Object type identifiers are used in ObjectCreate(), ObjectsDeleteAll() and ObjectType() functions.
|
||||||
|
|
||||||
|
Further specifications of object properties are possible using functions for working with graphical objects.
|
||||||
|
|
||||||
|
[Reference](https://docs.mql4.com/constants/objectconstants/enum_object)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# OnCalculate
|
||||||
|
|
||||||
|
The OnCalculate() function is called only in custom indicators when it's necessary to calculate the indicator values by the Calculate event. This usually happens when a new tick is received for the symbol, for which the indicator is calculated. This indicator is not required to be attached to any price chart of this symbol.
|
||||||
|
|
||||||
|
The OnCalculate() function must have a return type int.
|
||||||
|
|
||||||
|
```MQL4
|
||||||
|
int OnCalculate (
|
||||||
|
const int rates_total, // size of input time series
|
||||||
|
const int prev_calculated, // bars handled in previous call
|
||||||
|
const datetime& time[], // Time
|
||||||
|
const double& open[], // Open
|
||||||
|
const double& high[], // High
|
||||||
|
const double& low[], // Low
|
||||||
|
const double& close[], // Close
|
||||||
|
const long& tick_volume[], // Tick Volume
|
||||||
|
const long& volume[], // Real Volume
|
||||||
|
const int& spread[] // Spread
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
Parameters of open[], high[], low[] and close[] contain arrays with open prices, high and low prices and close prices of the current time frame. The time[] parameter contains an array with open time values, the spread[] parameter has an array containing the history of spreads (if any spread is provided for the traded security). The parameters of volume[] and tick_volume[] contain the history of trade and tick volume, respectively.
|
||||||
|
|
||||||
|
**Note**
|
||||||
|
To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.
|
||||||
|
|
||||||
|
**Note**
|
||||||
|
The first rates_total parameter contains the number of bars, available to the indicator for calculation, and corresponds to the number of bars available in the chart.
|
||||||
|
|
||||||
|
We should note the connection between the return value of OnCalculate() and the second input parameter prev_calculated. During the function call, the prev_calculated parameter contains a value returned by OnCalculate() during previous call. This allows for economical algorithms for calculating the custom indicator in order to avoid repeated calculations for those bars that haven't changed since the previous run of this function.
|
||||||
|
|
||||||
|
For this, it is usually enough to return the value of the rates_total parameter, which contains the number of bars in the current function call. If since the last call of OnCalculate() price data has changed (a deeper history downloaded or history blanks filled), the value of the input parameter prev_calculated will be set to zero by the terminal.
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# OnDeinit
|
||||||
|
|
||||||
|
The OnDeinit() function is called during deinitialization and is the Deinit event handler. It must be declared as the void type and should have one parameter of the const int type, which contains the code of deinitialization reason. If a different type is declared, the compiler will generate a warning, but the function will not be called.
|
||||||
|
|
||||||
|
The Deinit event is generated for Expert Advisors and indicators in the following cases:
|
||||||
|
|
||||||
|
before reinitialization due to the change of a symbol or chart period, to which the mql4 program is attached;
|
||||||
|
before reinitialization due to the change of input parameters;
|
||||||
|
before unloading the mql4 program.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
void OnDeinit(const int reason);
|
||||||
|
```
|
||||||
|
|
||||||
|
| Constant | Value | Description |
|
||||||
|
| -------- | ----- | ----------- |
|
||||||
|
| REASON_PROGRAM | 0 | Expert Advisor terminated its operation by calling the ExpertRemove() function|
|
||||||
|
| REASON_REMOVE | 1 | Program has been deleted from the chart |
|
||||||
|
| REASON_RECOMPILE | 2 | Program has been recompiled |
|
||||||
|
| REASON_CHARTCHANGE | 3 | Symbol or chart period has been changed |
|
||||||
|
| REASON_CHARTCLOSE | 4 | Chart has been closed |
|
||||||
|
| REASON_PARAMETERS | 5 | Input parameters have been changed by a user |
|
||||||
|
| REASON_ACCOUNT | 6 | Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings |
|
||||||
|
| REASON_TEMPLATE | 7 | A new template has been applied |
|
||||||
|
| REASON_INITFAILED | 8 | This value means that OnInit() handler has returned a nonzero value |
|
||||||
|
| REASON_CLOSE | 9 | Terminal has been closed |
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# OnInit
|
||||||
|
|
||||||
|
The Init event is generated immediately after an Expert Advisor or an indicator is downloaded; The OnInit() function is used for initialization. If OnInit() has the int type of the return value, the non-zero return code means unsuccessful initialization, and it generates the Deinit event with the code of deinitialization reason REASON_INITFAILED.
|
||||||
|
|
||||||
|
OnInit() function execution result is analyzed by the terminal's runtime subsystem only if the program has been compiled using #property strict.
|
||||||
|
|
||||||
|
INIT_SUCCEEDED
|
||||||
|
INIT_FAILED
|
||||||
|
INIT_PARAMETERS_INCORRECT
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# OnTick Event Handler Function
|
||||||
|
|
||||||
|
as i told before, this is main and most important event handler function in an EA.
|
||||||
|
|
||||||
|
each tick represent a price change, som during an EA there are some cases which same price or etc maybe occures twice or more.
|
||||||
|
we have to handle this situations to prevent double signaling, or opening positions more than once.
|
||||||
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
# OrderSend
|
||||||
|
|
||||||
|
[Trade Functions](https://docs.mql4.com/trading)
|
||||||
|
|
||||||
|
The main function used to open an order or place a pending order.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
int OrderSend(
|
||||||
|
string symbol, // symbol
|
||||||
|
int cmd, // operation
|
||||||
|
double volume, // volume
|
||||||
|
double price, // price
|
||||||
|
int slippage, // slippage
|
||||||
|
double stoploss, // stop loss
|
||||||
|
double takeprofit, // take profit
|
||||||
|
string comment=NULL, // comment
|
||||||
|
int magic=0, // magic number
|
||||||
|
datetime expiration=0, // pending order expiration
|
||||||
|
color arrow_color=clrNONE // color
|
||||||
|
);dg
|
||||||
|
```
|
||||||
|
|
||||||
|
## Order Properties (CMD)
|
||||||
|
|
||||||
|
| ID | Value | Description |
|
||||||
|
| -- | ----- | ----------- |
|
||||||
|
| OP_BUY | 0 | Buy operation |
|
||||||
|
| OP_SELL | 1 | Sell operation |
|
||||||
|
| OP_BUYLIMIT | 2 | Buy limit pending order |
|
||||||
|
| OP_SELLLIMIT | 3 | Sell limit pending order |
|
||||||
|
| OP_BUYSTOP | 4 | Buy stop pending order |
|
||||||
|
| OP_SELLSTOP | 5 | Sell stop pending order |
|
||||||
|
|
||||||
|
## Market Order
|
||||||
|
|
||||||
|
There are three types of orders that can be placed in MetaTrader: market, stop and limit orders. Being the most common, a market order opens a position immediately at the nearest Bid or Ask price.
|
||||||
|
|
||||||
|
### Buy
|
||||||
|
|
||||||
|
OrderSend(Symbol(),OP_BUY,0.1,Ask,2,Bid-15*Point,Bid+15*Point);
|
||||||
|
|
||||||
|
double bid =MarketInfo("GBPUSD",MODE_BID); // Request for the value of Bid
|
||||||
|
double ask =MarketInfo("GBPUSD",MODE_ASK); // Request for the value of Ask
|
||||||
|
double point =MarketInfo("GBPUSD",MODE_POINT);//Request for Point
|
||||||
|
// Opening BUY
|
||||||
|
OrderSend("GBPUSD",OP_BUY,0.1,ask,2,bid-15*Point,bid+15*Point);
|
||||||
|
Alert (GetLastError()); // Error message
|
||||||
|
return; // Exit start()
|
||||||
|
|
||||||
|
|
||||||
|
OrderSend (Symbol(), OP_BUY, Lots, Ask, Slippage, Bid-StopLoss *Point, Bid+TakeProfit*Point, “EAName”, MagicNumber, 0, Blue)
|
||||||
|
Here is an example of a sell market order:
|
||||||
|
|
||||||
|
### Sell
|
||||||
|
|
||||||
|
OrderSend (Symbol(), OP_SELL, Lots, Bid, Slippage, Ask+StopLoss *Point, Ask-TakeProfit*Point, “EAName”, MagicNumber, 0, Blue)
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Create a loop for rights
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
int OnCalculate(...) {
|
||||||
|
//
|
||||||
|
// wait to pass bars until we have rights ...
|
||||||
|
if (rates_total <= InpPeriod) {
|
||||||
|
//
|
||||||
|
// return not calculated ...
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// find loop count for bars manipulation ...
|
||||||
|
int count = (prev_calculated == 0) ? rates_total - InpPeriod - 1 : rates_total - prev_calculated + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is the main loop of calculations, for each bar index ...
|
||||||
|
for (int i = count - 1; i >= 0; i--) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// return current calculated ...
|
||||||
|
return rates_totlat;
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Define Plots using Compiler
|
||||||
|
|
||||||
|
```MQL
|
||||||
|
#property indicator_chart_window
|
||||||
|
#property indicator_buffers 1
|
||||||
|
|
||||||
|
//
|
||||||
|
//--- plot Line
|
||||||
|
#property indicator_label1 "Line"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrDarkBlue
|
||||||
|
#property indicator_style1 STYLE_SOLID
|
||||||
|
#property indicator_width1 1
|
||||||
|
```
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# Position Counting
|
||||||
|
|
||||||
|
- **PositionTotal()**: counts all positions;
|
||||||
|
- **OrdersTotal()**: counts all orders;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# PositionGetTicket
|
||||||
|
|
||||||
|
it is a function which get position index and retrieve and returns the specified position ticket ...
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# PositionsTotal
|
||||||
|
|
||||||
|
a function which returns number of open position
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# Print
|
||||||
|
|
||||||
|
this command used to show some data in MT Log window.
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# RMA
|
||||||
|
|
||||||
|
Relative Moving Average (RMA) with the ta.rma() function.
|
||||||
|
|
||||||
|
A Relative Moving Average adds more weight to recent data (and gives less importance to older data). This makes the RMA similar to the Exponential Moving Average, although it’s somewhat slower to respond than an EMA is.
|
||||||
|
|
||||||
|
ta.rma(source, length)
|
||||||
|
|
||||||
|
source is the series of numerical values to process. It’s the (price) data we calculate the RMA on.
|
||||||
|
length is an integer with the moving average length in bars. This is the lookback period over which Pine Script calculates the average.
|
||||||
|
ta.rma() returns the Relative Moving Average as a floating-point value [1] .
|
||||||
|
|
||||||
|
The RMA is obtained by dividing a stock's short-term moving average of price by its long-term moving average of price. Stocks rising in price the fastest always have the highest RMAs, and those going down in price the fastest always have the lowest RMAs.
|
||||||
|
|
||||||
|
[Formula](https://www.hybrid-solutions.com/plugins/client-vtl-plugins/free/rma.html)
|
||||||
|
|
||||||
|
This indicator represents the relative moving average indicator (RMA). RMA = SMA(3 x Period) - SMA(2 x Period) + SMA(1 x Period) per formula: https://www.hybrid-solutions.com/plugins/client-vtl-plugins/free/rma.html
|
||||||
|
|
||||||
|
ShortAverage = new SimpleMovingAverage(name + "_Short", period);
|
||||||
|
MediumAverage = new SimpleMovingAverage(name + "_Medium", period * 2);
|
||||||
|
LongAverage = new SimpleMovingAverage(name + "_Long", period * 3);
|
||||||
|
|
||||||
|
LongAverage.Current.Value - MediumAverage.Current.Value + ShortAverage.Current.Value;
|
||||||
|
|
||||||
|
rma = sma(price,period*3) + sma (price,period*2) - sma(price,period)
|
||||||
|
|
||||||
|
[Fromula 1](https://www.tradingcode.net/tradingview/relative-moving-average/)
|
||||||
|
|
||||||
|
alpha = 1 / length
|
||||||
|
|
||||||
|
rma = alpha * source + (1 - alpha) * RMA[1]
|
||||||
|
|
||||||
|
pine_rma(source, length) =>
|
||||||
|
alpha = 1 / length
|
||||||
|
sum = 0.0
|
||||||
|
sum := na(sum[1]) ?
|
||||||
|
ta.sma(source, length) :
|
||||||
|
alpha * source + (1 - alpha) * nz(sum[1])
|
||||||
|
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
# RSI MA Cross Strategy
|
||||||
|
|
||||||
|
EURUSD M15 Chart is Open
|
||||||
|
|
||||||
|
## Strategy Used
|
||||||
|
|
||||||
|
- 10 Period RSI:
|
||||||
|
- ;
|
||||||
|
- ;
|
||||||
|
- 5 Period EMA;
|
||||||
|
- 10 Period MA;
|
||||||
|
|
||||||
|
works by over solde and over baughts on rsi and then check mas;
|
||||||
|
|
||||||
|
## Implementation
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Fast MA ...
|
||||||
|
input int fastMaPeriod = 20; // Fast MA Bars
|
||||||
|
input ENUM_MA_METHOD fastMaMethod = MODE_EMA; // Fast MA Method
|
||||||
|
input ENUM_APPLIED_PRICE fastMaAppliedPrice = PRICE_CLOSE; // Fast MA Applied Price
|
||||||
|
|
||||||
|
//
|
||||||
|
// Slow MA ...
|
||||||
|
input int slowMaPeriod = 50; // Slow MA Bars
|
||||||
|
input ENUM_MA_METHOD slowMaMethod = MODE_EMA; // Slow MA Method
|
||||||
|
input ENUM_APPLIED_PRICE slowMaAppliedPrice = PRICE_CLOSE; // Slow MA Applied Price
|
||||||
|
|
||||||
|
//
|
||||||
|
// SL / TP ...
|
||||||
|
input int stopLossPips = 50; // SL Pips
|
||||||
|
input int takeProfitPips = 50; // TP Pips
|
||||||
|
|
||||||
|
//
|
||||||
|
// Trade ...
|
||||||
|
intput double orderSize = 0.01; // Order size in Lots
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
double fastMaBuffer[];
|
||||||
|
double slowMaBuffer[];
|
||||||
|
|
||||||
|
const int buffersValuesRequired = 3;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Global Variables ...
|
||||||
|
double stopLoss;
|
||||||
|
double takeProfit;
|
||||||
|
|
||||||
|
//
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
stopLoss = PipsToDouble(stopLossPips);
|
||||||
|
takeProfit = PipsToDouble(takeProfitPips);
|
||||||
|
|
||||||
|
//
|
||||||
|
IsNewBar();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Calculating SL and TP Gaps on Trading Open
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Define Some Variables ...
|
||||||
|
double price;
|
||||||
|
double closePrice;
|
||||||
|
double tp = 0;
|
||||||
|
double sl = 0;
|
||||||
|
double slGap = PointsToDouble((int) SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL));
|
||||||
|
|
||||||
|
//
|
||||||
|
if (stopLoss > 0 && stopLoss < slGap) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (takeProfit > 0 && takeProfit < slGap) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
RefreshRates();
|
||||||
|
|
||||||
|
//
|
||||||
|
if (type == ORDER_TYPE_BUY) {
|
||||||
|
//
|
||||||
|
price = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
|
||||||
|
closePrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (stopLoss > 0) {
|
||||||
|
sl = closePrice - stopLoss;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (takeProfit > 0) {
|
||||||
|
tp = price + takeProfit;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
price = SymbolInfoDouble(_Symbol, SYMBOL_BID);
|
||||||
|
closePrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (stopLoss > 0) {
|
||||||
|
sl = closePrice + stopLoss;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
if (takeProfit > 0) {
|
||||||
|
tp = price - takeProfit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
price = NormalizeDouble(price, _Digits);
|
||||||
|
sl = NormalizeDouble(sl, _Digits);
|
||||||
|
tp = NormalizeDouble(tp, _Digits);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usefull Library Methods
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Convert points to Actual Point ...
|
||||||
|
double PointsToDouble(int points) {
|
||||||
|
//
|
||||||
|
double result = points * _Point;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Converts Pips to Points ...
|
||||||
|
int PipsToPoints(int pips) {
|
||||||
|
//
|
||||||
|
int result = pips * ((_Digits == 3 || _Digits == 5) ? 10 : 1);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Converts Pips to Double ...
|
||||||
|
double PipsToDouble(int pips) {
|
||||||
|
//
|
||||||
|
double result = PointsToDouble(PipsToPoints(pips));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# SMA
|
||||||
|
|
||||||
|
Simple Moving Average
|
||||||
|
|
||||||
|
[Resource 1](https://www.investopedia.com/terms/s/sma.asp)
|
||||||
|
|
||||||
|
A simple moving average (SMA) calculates the average of a selected range of prices, usually closing prices, by the number of periods in that range.
|
||||||
|
|
||||||
|
Simple moving averages calculate the average of a range of prices by the number of periods within that range.
|
||||||
|
A simple moving average is a technical indicator that can aid in determining if an asset price will continue or if it will reverse a bull or bear trend.
|
||||||
|
A simple moving average can be enhanced as an exponential moving average (EMA) that is more heavily weighted on recent price action.
|
||||||
|
|
||||||
|
## Formula
|
||||||
|
|
||||||
|
SMA = (A1 + A2 + ... + An) / n
|
||||||
|
|
||||||
|
An = price of an asset at period n
|
||||||
|
n = the number of total periods
|
||||||
|
|
||||||
|
[Tutorial](https://mql4tutorial.com/mql4-tutorial-english/mql4-tutorial-basics-11-how-to-calculate-a-simple-moving-average)
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
double sma = iMA(_Symbol, _Period, numOfCandles, 0, MODE_SMA, PRICE_CLOSE, 0)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Calculation process
|
||||||
|
|
||||||
|
```pine
|
||||||
|
pine_sma(source, length) =>
|
||||||
|
sum = 0.0
|
||||||
|
for i = 0 to length - 1
|
||||||
|
sum += source[i] / length
|
||||||
|
sum
|
||||||
|
|
||||||
|
plot(pine_sma(close, 15))
|
||||||
|
```
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
# Some Usefull Tutorials
|
||||||
|
|
||||||
|
## Open Order
|
||||||
|
|
||||||
|
for opening a sample order in mql4 follow following syntax:
|
||||||
|
|
||||||
|
//
|
||||||
|
buy => ASK Price ...
|
||||||
|
sell => BID Price ...
|
||||||
|
|
||||||
|
```mql4
|
||||||
|
void OnTick() {
|
||||||
|
//
|
||||||
|
if (OrdersTotal() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// we are on bullish candle ...
|
||||||
|
if (close[1] > open[1]) {
|
||||||
|
//
|
||||||
|
OrderSend(
|
||||||
|
_Symbol, // Symbol ...
|
||||||
|
OP_BUY, // Operation ...
|
||||||
|
0.1 // Lot Size ( Volume ) ...
|
||||||
|
Ask, // Open Order Price ...
|
||||||
|
3, // tolerance ...
|
||||||
|
Ask - 300 * _Point, // SL ...
|
||||||
|
Ask + 150 * _Point, // TP ...
|
||||||
|
NULL, // Trade Comment ...
|
||||||
|
0, // Magic Number (user unique number) ...
|
||||||
|
0, // Expiration ...
|
||||||
|
Green // Arrow Line ...
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Counting Open Buy Positions
|
||||||
|
|
||||||
|
```mql4
|
||||||
|
int CountOpenBuyOrders() {
|
||||||
|
//
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = OrdersTotal() - 1; i >= 0; i--) {
|
||||||
|
//
|
||||||
|
OrderSelect(i, SELECT_BY_POSITION, MODE_TRADES);
|
||||||
|
|
||||||
|
//
|
||||||
|
string orderSymbol = OrderSymbol();
|
||||||
|
|
||||||
|
//
|
||||||
|
if (
|
||||||
|
orderSymbol == _Symbol &&
|
||||||
|
OrderType() == OP_BUY
|
||||||
|
) {
|
||||||
|
result++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Oscillator
|
||||||
|
|
||||||
|
usually oscillators is visualized some additional data related to chart, but not price momentums, and drwn on spearate window by default.
|
||||||
|
specially works on volumes.
|
||||||
|
|
||||||
@@ -0,0 +1,221 @@
|
|||||||
|
# Indicator
|
||||||
|
|
||||||
|
usually indicators is visualized some additional data on chart, and drwn on candle charts by default.
|
||||||
|
specially works on prices.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#property indicator_buffers numOfBuffers
|
||||||
|
```
|
||||||
|
|
||||||
|
for example:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#property indicator_buffers 2
|
||||||
|
```
|
||||||
|
|
||||||
|
here we define 2 buffer to system for processing in each candle ...
|
||||||
|
|
||||||
|
then we have to define arrays ...
|
||||||
|
|
||||||
|
double BufferFast[];
|
||||||
|
double BufferSlow[];
|
||||||
|
|
||||||
|
usually for each indicator buffers we can define a constant to hold it's index on chart queue.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#define FastIndicator 0
|
||||||
|
#define SlowIndicator 1
|
||||||
|
```
|
||||||
|
|
||||||
|
each buffer holds data to use in candle calculation time and then draw things on chart.
|
||||||
|
|
||||||
|
we have to define Indexes for Buffers to draw themon chart.
|
||||||
|
this happens on OnInit() event handler method.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Fast Indicator ...
|
||||||
|
SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_DOT, 1, clrFireBrick);
|
||||||
|
SetIndexBuffer(FastIndicator, BufferFast);
|
||||||
|
SetIndexLabel(FastIndicator, "Fast");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Slow Indicator ...
|
||||||
|
SetIndexStyle(SlowIndicator, DRAW_LINE, STYLE_DOT, 1, clrGreen);
|
||||||
|
SetIndexBuffer(SlowIndicator, BufferSlow);
|
||||||
|
SetIndexLabel(SlowIndicator, "Slow");
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
after define styling of indicators parts, we have to fill buffers by required data's, in OnCalculate() event handler.
|
||||||
|
since at initialization time, there is no data in Buffers to use them.
|
||||||
|
|
||||||
|
in OnCalculate event handler, also some usefull args and params to use them for calculation steps or implement our business logic.
|
||||||
|
|
||||||
|
if you need to know them completely, see proppered documentation file.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
int OnCalculate(
|
||||||
|
const int rates_total, // size of input time series
|
||||||
|
const int prev_calculated, // bars handled in previous call
|
||||||
|
const datetime& time[], // Time
|
||||||
|
const double& open[], // Open
|
||||||
|
const double& high[], // High
|
||||||
|
const double& low[], // Low
|
||||||
|
const double& close[], // Close
|
||||||
|
const long& tick_volume[], // Tick Volume
|
||||||
|
const long& volume[], // Real Volume
|
||||||
|
const int& spread[] // Spread
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// Here we defined some variables to use them ...
|
||||||
|
int limit;
|
||||||
|
double signalMa,
|
||||||
|
fastMa,
|
||||||
|
slowMa;
|
||||||
|
|
||||||
|
//
|
||||||
|
// in this example, SlowMAPeriod is an input for
|
||||||
|
// using in Calculations ...
|
||||||
|
// so as we don't reach to this input candle, we cant calculate
|
||||||
|
// anything ...
|
||||||
|
// for this reasin we check rates_total param, and if not reach to our
|
||||||
|
// input variable, we return 0 means nothing passed ...
|
||||||
|
if (rates_total <= SlowMAPeriod) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// found which candles calculated before ...
|
||||||
|
limit = rates_total - prev_calculated;
|
||||||
|
if (prev_calculated>0) {
|
||||||
|
limit++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do Calculation ...
|
||||||
|
// Symbol() => retrieve current chart window symbol ...
|
||||||
|
// Period() => retrieve current period ...
|
||||||
|
for (int i = limit - 1; i>0; i--) {
|
||||||
|
//
|
||||||
|
signalMa = iMa(Symbol(), Period(), SignalMaPeriod, 0, MAMethod, PRICE_CLOSE, i);
|
||||||
|
|
||||||
|
//
|
||||||
|
fastMa = iMa(Symbol(), Period(), FastMaPeriod, 0, MAMethod, PRICE_CLOSE, i);
|
||||||
|
|
||||||
|
//
|
||||||
|
slowMa = iMa(Symbol(), Period(), SlowMaPeriod, 0, MAMethod, PRICE_CLOSE, i);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Here we have to do some calculation, and check some conditions, then
|
||||||
|
// fill up buffers based on conditions ...
|
||||||
|
// Trending Up Condition ...
|
||||||
|
if (signalMa > fastMa && fastMa < slowMa) {
|
||||||
|
//
|
||||||
|
BufferFast[i] = fastMa;
|
||||||
|
BufferSlow[i] = slowMa;
|
||||||
|
//
|
||||||
|
// Trending Down Condition ...
|
||||||
|
} else if (signalMa < fastMa && fastMa < slowMa>) {
|
||||||
|
//
|
||||||
|
BufferFast[i] = fastMa;
|
||||||
|
BufferSlow[i] = slowMa;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// NOTE: it could be possible to combine above two condition, but
|
||||||
|
// we separate them for learning purposed ...
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// this tells meta trader how many candles we used ...
|
||||||
|
return rate_total;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
in above example we just show two line, and there is no histogram.
|
||||||
|
in mt4 for drawing histogram we have to do some unusual works ...
|
||||||
|
|
||||||
|
we are going to complete the example to support histogram.
|
||||||
|
|
||||||
|
for showing histogram, we need two more buffers.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
//
|
||||||
|
// Increase System Defined Buffers ...
|
||||||
|
#property indicator_buffers 4
|
||||||
|
|
||||||
|
//
|
||||||
|
// Next we have to define two more Buffer ...
|
||||||
|
double BufferUp[];
|
||||||
|
double BufferDown[];
|
||||||
|
|
||||||
|
//
|
||||||
|
// then we have to change definition of indexes of buffers for supporting histograms ...
|
||||||
|
// wen MT draws Histogram, it's used area between next indicator and selected one ...
|
||||||
|
#define UpIndicator 0
|
||||||
|
#define DownIndicator 2
|
||||||
|
#define FastIndicator 3
|
||||||
|
#define SlowIndicator 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Then we have to define Styling for histogram ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Fast Indicator ...
|
||||||
|
SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_DOT, 1, clrFireBrick);
|
||||||
|
SetIndexBuffer(FastIndicator, BufferFast);
|
||||||
|
SetIndexLabel(FastIndicator, "Fast");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Slow Indicator ...
|
||||||
|
SetIndexStyle(SlowIndicator, DRAW_LINE, STYLE_DOT, 1, clrGreen);
|
||||||
|
SetIndexBuffer(SlowIndicator, BufferSlow);
|
||||||
|
SetIndexLabel(SlowIndicator, "Slow");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Up Indicator ...
|
||||||
|
SetIndexStyle(UpIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrGreen);
|
||||||
|
SetIndexBuffer(UpIndicator, BufferUp);
|
||||||
|
SetIndexEmptyValue(UpIndicator, 0.0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Down Indicator ...
|
||||||
|
SetIndexStyle(DownIndicator, DRAW_HISTOGRAM, STYLE_DOT, 1, clrFireBrick);
|
||||||
|
SetIndexBuffer(DownIndicator, BufferDown);
|
||||||
|
SetIndexEmptyValue(DownIndicator, 0.0);
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// then we have to change calculation for filling bufferup and bufferdown ...
|
||||||
|
//
|
||||||
|
// the reason which we separate this conditions, for drawing histograms ...
|
||||||
|
// Trending Up Condition ...
|
||||||
|
if (signalMa > fastMa && fastMa < slowMa) {
|
||||||
|
//
|
||||||
|
BufferFast[i] = fastMa;
|
||||||
|
BufferSlow[i] = slowMa;
|
||||||
|
|
||||||
|
//
|
||||||
|
// the histogram drawn between fast line and slow line ...
|
||||||
|
// so up indicator draws between itself and slow ...
|
||||||
|
BufferUp[i] = fastMa;
|
||||||
|
//
|
||||||
|
// Trending Down Condition ...
|
||||||
|
} else if (signalMa < fastMa && fastMa < slowMa>) {
|
||||||
|
//
|
||||||
|
BufferFast[i] = fastMa;
|
||||||
|
BufferSlow[i] = slowMa;
|
||||||
|
|
||||||
|
//
|
||||||
|
// the histogram drawn between slow line and fast line ...
|
||||||
|
// so up indicator draws between itself and fast ...
|
||||||
|
BufferDown[i] = slowMa;
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Slope
|
||||||
|
|
||||||
|
Shib
|
||||||
|
|
||||||
|
m = (y2 - y1) / (x2 - x1)
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
# Stochastic EA
|
||||||
|
|
||||||
|
we want to buy on bottom of stochastic when cross over stock with signal
|
||||||
|
and sell when cross under stock with signall on top ...
|
||||||
|
|
||||||
|
```mql4
|
||||||
|
//
|
||||||
|
int totalBars;
|
||||||
|
|
||||||
|
//
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
totalBars = iBars(Symbol, _Period);
|
||||||
|
|
||||||
|
//
|
||||||
|
...
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
void OnTick() {
|
||||||
|
//
|
||||||
|
int bars = iBars(_Symbol, _Period);
|
||||||
|
if (totlaBars != bars) {
|
||||||
|
//
|
||||||
|
totalBars = bars;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do Actions here ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
# SymbolInfoDouble
|
||||||
|
|
||||||
|
[Reference](https://docs.mql4.com/marketinformation/symbolinfodouble);
|
||||||
|
|
||||||
|
Returns the corresponding property of a specified symbol. There are 2 variants of the function.
|
||||||
|
|
||||||
|
1. Immediately returns the property value.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
double SymbolInfoDouble(
|
||||||
|
string name, // symbol
|
||||||
|
ENUM_SYMBOL_INFO_DOUBLE prop_id // identifier of the property
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Returns true or false depending on whether a function is successfully performed. In case of success, the value of the property is placed into a recipient variable, passed by reference by the last parameter.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
bool SymbolInfoDouble(
|
||||||
|
string name, // symbol
|
||||||
|
ENUM_SYMBOL_INFO_DOUBLE prop_id, // identifier of the property
|
||||||
|
double& double_var // here we accept the property value
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
|
||||||
|
name
|
||||||
|
|
||||||
|
[in] Symbol name.
|
||||||
|
|
||||||
|
prop_id
|
||||||
|
|
||||||
|
[in] Identifier of a symbol property. The value can be one of the values of the ENUM_SYMBOL_INFO_DOUBLE enumeration.
|
||||||
|
|
||||||
|
double_var
|
||||||
|
|
||||||
|
[out] Variable of double type receiving the value of the requested property.
|
||||||
|
|
||||||
|
Return Value
|
||||||
|
|
||||||
|
The value of double type. In case of execution failure, information about the error can be obtained using GetLastError() function:
|
||||||
|
|
||||||
|
4106 — symbol is not selected in "Market Watch" (not found in the list of available ones),
|
||||||
|
4051 — invalid identifier of a symbol property,
|
||||||
|
4024 — internal error.
|
||||||
|
Note
|
||||||
|
|
||||||
|
It is recommended to use SymbolInfoTick() if the function is used for getting information about the last tick. It may well be that not a single quote has appeared yet since the terminal is connected to a trading account. In such a case, the requested value will be indefinite.
|
||||||
|
|
||||||
|
In most cases, it is enough to use SymbolInfoTick() function allowing a user to receive the values of Ask, Bid, Last, Volume and the time of the last tick's arrival during a single call.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
void OnTick()
|
||||||
|
{
|
||||||
|
//--- obtain spread from the symbol properties
|
||||||
|
bool spreadfloat=SymbolInfoInteger(Symbol(),SYMBOL_SPREAD_FLOAT);
|
||||||
|
string comm=StringFormat("Spread %s = %I64d points\r\n",
|
||||||
|
spreadfloat?"floating":"fixed",
|
||||||
|
SymbolInfoInteger(Symbol(),SYMBOL_SPREAD));
|
||||||
|
//--- now let's calculate the spread by ourselves
|
||||||
|
double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);
|
||||||
|
double bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
|
||||||
|
double spread=ask-bid;
|
||||||
|
int spread_points=(int)MathRound(spread/SymbolInfoDouble(Symbol(),SYMBOL_POINT));
|
||||||
|
comm=comm+"Calculated spread = "+(string)spread_points+" points";
|
||||||
|
Comment(comm);
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# How to Calculate TP based on SL and Risk To Reward Ratio
|
||||||
|
|
||||||
|
```solo
|
||||||
|
// Long:
|
||||||
|
//
|
||||||
|
// ask Price: 1.14443
|
||||||
|
// sl: 1.14325
|
||||||
|
// tp: 1.14620
|
||||||
|
// risk: askprice - sl = 0.00118
|
||||||
|
// reward: risk * ration = 0.00177
|
||||||
|
// tp: ask + reward
|
||||||
|
//
|
||||||
|
// Short:
|
||||||
|
//
|
||||||
|
// ask price: 1.14214
|
||||||
|
// sl: 1.14325
|
||||||
|
// tp: 1.14048
|
||||||
|
//
|
||||||
|
// risk: sl - ask = 0.00111
|
||||||
|
// reward: risk * ration = 0.001665
|
||||||
|
// tp: ask - reward
|
||||||
|
```
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# Trade Libnrary
|
||||||
|
|
||||||
|
a built-in library in MQL which is used to manipulate and manage Trade Positions in Expert Advisors.
|
||||||
|
|
||||||
|
for using this library, at the first step yopu have to include it oin your EA. this happens like this:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#include <Trade/Trade.mqh>
|
||||||
|
```
|
||||||
|
|
||||||
|
then you can access to it's provided stuffs.
|
||||||
|
|
||||||
|
## CTrade
|
||||||
|
|
||||||
|
it is a Class, which provides Trading Management functionalities for MQL Programmers ...
|
||||||
|
|
||||||
|
[here](https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade) are it's documentation.
|
||||||
|
|
||||||
|
this class is an static class and there is no need to call any constructor for it's usage. simple making it's instance by assigning a name to it's type:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
CTrade trader;
|
||||||
|
```
|
||||||
|
|
||||||
|
now you can acssess to all of it's provided actions, methods and etc to manipulate trade positions ...
|
||||||
|
|
||||||
|
**NOTE** for using this class you have to enable Auto Trading and also for your EA check it's checkbox for allow AutoTrading ...
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# Best Way to Code Trade Once per Bar at Open on MT4
|
||||||
|
|
||||||
|
So there are various ways to code an EA to trade once per bar.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
int BarsCount = 0;
|
||||||
|
if (Bars>BarsCount) {
|
||||||
|
Do the algo and then
|
||||||
|
BarsCount = Bars;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
static datetime prevtime = 0;
|
||||||
|
if(prevtime == Time[0]) return;
|
||||||
|
prevtime = Time[0];
|
||||||
|
Do the algo here after the code
|
||||||
|
```
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
if (Time[0] >= TimeCurrent()) {
|
||||||
|
Do the algo here
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
int BarsCount = 0
|
||||||
|
if (Bars>BarsCount) etc.
|
||||||
|
```
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
static datetime prevtime = Time[0];
|
||||||
|
if (prevtime == Time[0]) return;
|
||||||
|
prevtime = Time[0];
|
||||||
|
```
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
```
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# VWMA
|
||||||
|
|
||||||
|
Volume-Weighted Moving Average (VWMA)
|
||||||
|
|
||||||
|
## Calculation process
|
||||||
|
|
||||||
|
TradingView calculates the Volume-Weighted Moving Average with two Simple Moving Averages (SMAs) [1] . The first SMA multiplies each bar’s data with that bar’s volume. The second SMA is the volume average. Dividing those gives the VWMA.
|
||||||
|
|
||||||
|
```pine
|
||||||
|
pine_vwma(source, length) =>
|
||||||
|
ta.sma(source * volume, length) / ta.sma(volume, length)
|
||||||
|
```
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# _Point
|
||||||
|
|
||||||
|
[Resource](https://docs.mql4.com/predefined/_point)
|
||||||
|
|
||||||
|
The _Point variable contains the point size of the current symbol in the quote currency.
|
||||||
|
|
||||||
|
You may also use the Point() function.
|
||||||
|
|
||||||
|
smallest price changes corresponding to Symbol
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# iBarShift
|
||||||
|
|
||||||
|
Search for a bar by its time. The function returns the index of the bar which covers the specified time.
|
||||||
|
|
||||||
|
[Resource](https://docs.mql4.com/series/ibarshift)
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
# iCustom
|
||||||
|
|
||||||
|
Calculates the specified custom indicator and returns its value.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
double iCustom(
|
||||||
|
string symbol, // symbol
|
||||||
|
int timeframe, // timeframe
|
||||||
|
string name, // path/name of the custom indicator compiled program
|
||||||
|
... // custom indicator input parameters (if necessary)
|
||||||
|
int mode, // line index
|
||||||
|
int shift // shift
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
- **symbol** - Symbol name on the data of which the indicator will be calculated. NULL means the current symbol.
|
||||||
|
- **timeframe** - Timeframe. It can be any of ENUM_TIMEFRAMES enumeration values. 0 means the current chart timeframe.
|
||||||
|
- **name** - Custom indicator compiled program name, relative to the root indicators directory (MQL4/Indicators/). If the indicator is located in subdirectory, for example, in MQL4/Indicators/Examples, its name must be specified as "Examples\\indicator_name" (double backslash "\\"must be specified as separator instead of a single one).
|
||||||
|
- **...** -Custom indicator input-parameters, separated by commas.
|
||||||
|
|
||||||
|
The passed parameters and their order must correspond with the declaration order and the type of extern variables of the custom indicator. If the values of input parameters is not specified, the default values will be used.
|
||||||
|
|
||||||
|
- **mode** - Line index. Can be from 0 to 7 and must correspond with the index, specified in call of the SetIndexBuffer() function.
|
||||||
|
- **shift** - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
|
||||||
|
|
||||||
|
## Returned value
|
||||||
|
|
||||||
|
Numerical value of the specified custom indicator. The custom indicator must be compiled (*.EX4 file) and be in the terminal_directory\MQL4\Indicators\ directory.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
double val=iCustom(NULL,0,"SampleInd",13,1,0);
|
||||||
|
```
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Including files
|
||||||
|
|
||||||
|
in MQL Language we can put some functions on separated files, then include them in our main MQL Program (such as Indicator or EA) ...
|
||||||
|
then we can call it's functions ...
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#include "file.mq4"
|
||||||
|
```
|
||||||
|
|
||||||
|
see Library file ...
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
# Buffers
|
||||||
|
|
||||||
|
simply they are arrays which store information for using them as series in candles ...
|
||||||
|
in each mql program you had to define which buffers youi have to use in your program.
|
||||||
|
|
||||||
|
this happens by the following pattern
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#property indicator_buffers numOfBuffers
|
||||||
|
```
|
||||||
|
|
||||||
|
for example:
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#property indicator_buffers 2
|
||||||
|
```
|
||||||
|
here we define 2 buffer to system for processing in each candle ...
|
||||||
|
|
||||||
|
then we have to define arrays ...
|
||||||
|
|
||||||
|
double BufferFast[];
|
||||||
|
double BufferSlow[];
|
||||||
|
|
||||||
|
usually for each indicator buffers we can define a constant to hold it's index on chart queue.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
#define FastIndicator 0
|
||||||
|
#define SlowIndicator 1
|
||||||
|
```
|
||||||
|
|
||||||
|
each buffer holds data to use in candle calculation time and then draw things on chart.
|
||||||
|
|
||||||
|
we have to define Indexes for Buffers to draw themon chart.
|
||||||
|
this happens on OnInit() event handler method.
|
||||||
|
|
||||||
|
```mq4
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Fast Indicator ...
|
||||||
|
SetIndexStyle(FastIndicator, DRAW_LINE, STYLE_DOT, 1, clrFireBrick);
|
||||||
|
SetIndexBuffer(FastIndicator, BufferFast);
|
||||||
|
SetIndexLabel(FastIndicator, "Fast");
|
||||||
|
|
||||||
|
//
|
||||||
|
// Slow Indicator ...
|
||||||
|
SetIndexStyle(SlowIndicator, DRAW_LINE, STYLE_DOT, 1, clrGreen);
|
||||||
|
SetIndexBuffer(SlowIndicator, BufferSlow);
|
||||||
|
SetIndexLabel(SlowIndicator, "Slow");
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
```
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# nz
|
||||||
|
|
||||||
|
nz is a “filler”, as it fills na values of a series with zeros (in the case of nz(x) ) or with a user-specified value (in the case of nz(x, y) ).
|
||||||
|
|
||||||
|
[Resources](https://www.tradingview.com/pine-script-docs/en/v3/language/Expressions_declarations_and_statements.html#preventing-na-values-functions-na-and-nz)
|
||||||
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Property
|
||||||
|
|
||||||
|
[Resource](https://docs.mql4.com/basis/preprosessor/compilation)
|
||||||
|
|
||||||
|
Every MQL4-program allows to specify additional specific parameters named #property that help client terminal in proper servicing for programs without the necessity to launch them explicitly. This concerns external settings of indicators, first of all. Properties described in included files are completely ignored. Properties must be specified in the main mq4 file.
|
||||||
|
|
||||||
|
#property identifier value
|
||||||
|
|
||||||
|
The compiler will write declared values in the configuration of the module executed.
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
var label l = na
|
||||||
|
if (barstate.islast)
|
||||||
|
l := label.new(bar_index, high, text="CE ATR Multiplier: " + str.tostring(chandelierExitATRMultiplier))
|
||||||
|
label.delete(l[1])
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
# Support and Resistance Scalping (XTS_SR15M)
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
- **TF**: 15m
|
||||||
|
- **Asset**: AAPL
|
||||||
|
- **R2R**: 1:1.5
|
||||||
|
- **Indicators**:
|
||||||
|
- Leledc Levels (IS) InSillico:
|
||||||
|
- Change Exhaustion bar count to 42;
|
||||||
|
- Change Line Tickness to 7;
|
||||||
|
- Hide Support Level line;
|
||||||
|
- Hide Resistance Level linel;
|
||||||
|
- ATR Stop Loss garethyeo:
|
||||||
|
- Change Source to low;
|
||||||
|
- **Oscillators**:
|
||||||
|
- Kurutoga Histogram (D7R):
|
||||||
|
- Hide Kurutuga Lead 4x;
|
||||||
|
|
||||||
|
## Descriptions
|
||||||
|
|
||||||
|
since Kurutoga Histogram doesn't provides it's source code, i try to implement
|
||||||
|
Cycle Channel Oscillator, instead of it.
|
||||||
|
|
||||||
|
after i try to do back testing usage of CCH and KUH, i found this rules:
|
||||||
|
|
||||||
|
- kurutuga histogram green color, means both red and green line in Cycle Channel must be above than 0.5 (Middle) line and green line above than red line.
|
||||||
|
- kurutuga histogram red color, means both red and green line in Cycle Channel must be below than 0.5 (Middle) line and red line below than green line.
|
||||||
|
|
||||||
|
so we have to implement cycle channel oscillator and it's verifications on signals ...
|
||||||
|
|
||||||
|
## Using the Strategy
|
||||||
|
|
||||||
|
### Long/Buy Conditions
|
||||||
|
|
||||||
|
- Leledc Level gives **Support Signal** (green to up side triangle);
|
||||||
|
- kurutuga histogram is **red** color;
|
||||||
|
- market forms a **bullish** candle;
|
||||||
|
|
||||||
|
#### Long SL
|
||||||
|
|
||||||
|
place sl at low of ATR Stop Loss Purple(red) Line.
|
||||||
|
|
||||||
|
#### Long TP
|
||||||
|
|
||||||
|
calculate based on R2R;
|
||||||
|
|
||||||
|
### Short/Sell Conditions
|
||||||
|
|
||||||
|
- Leledc Level gives **Resistance Signal** (red to down side triangle);
|
||||||
|
- kurutuga histogram is **green** color;
|
||||||
|
- market forms a **bearish** candle;
|
||||||
|
|
||||||
|
#### Short SL
|
||||||
|
|
||||||
|
place sl at high of ATR Stop Loss Green Line.
|
||||||
|
|
||||||
|
#### Short TP
|
||||||
|
|
||||||
|
calculate based on R2R;
|
||||||
|
|
||||||
|
### Signals Overlap
|
||||||
|
|
||||||
|
how to handle signals overlaps.
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
// //
|
||||||
|
// // Long Signal ...
|
||||||
|
// if (
|
||||||
|
// //
|
||||||
|
// hasLongSignal &&
|
||||||
|
// //
|
||||||
|
// price <xmaLow &&
|
||||||
|
// cLow < xmaLow &&
|
||||||
|
// cHigh < xmaLow &&
|
||||||
|
// price < xmaBigHigh &&
|
||||||
|
// tp > xmaBigHigh &&
|
||||||
|
// tp > xmaHigh
|
||||||
|
// ) {
|
||||||
|
// tp = MathMin(xmaHigh, xmaBigHigh);
|
||||||
|
// } else
|
||||||
|
// //
|
||||||
|
// // Short Signal ...
|
||||||
|
// // TODO: Change ...
|
||||||
|
// if (
|
||||||
|
// //
|
||||||
|
// hasShortSignal &&
|
||||||
|
// //
|
||||||
|
// price < xmaHigh &&
|
||||||
|
// price < xmaBigHigh &&
|
||||||
|
// price > xmaLow &&
|
||||||
|
// //
|
||||||
|
// tp < xmaLow
|
||||||
|
// ) {
|
||||||
|
// tp = xmaLow;
|
||||||
|
// }
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
## Strategy Title
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
|
||||||
|
- **TF**:
|
||||||
|
- **Asset**:
|
||||||
|
- **R2R**: 1:1.5
|
||||||
|
- **Indicators**:
|
||||||
|
--
|
||||||
|
--
|
||||||
|
- **Oscillators**:
|
||||||
|
--
|
||||||
|
|
||||||
|
### Using the Strategy
|
||||||
|
|
||||||
|
#### Long/Buy Conditions
|
||||||
|
|
||||||
|
- ;
|
||||||
|
|
||||||
|
##### Long SL
|
||||||
|
|
||||||
|
place sl below of previous market.
|
||||||
|
|
||||||
|
##### Long TP
|
||||||
|
|
||||||
|
calculate based on R2R;
|
||||||
|
|
||||||
|
#### Short/Sell Conditions
|
||||||
|
|
||||||
|
- ;
|
||||||
|
|
||||||
|
##### Short SL
|
||||||
|
|
||||||
|
place sl below of previous market.
|
||||||
|
|
||||||
|
##### Short TP
|
||||||
|
|
||||||
|
calculate based on R2R;
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
# XST_???
|
||||||
|
|
||||||
|
## Report
|
||||||
|
|
||||||
|
### Makret
|
||||||
|
|
||||||
|
???
|
||||||
|
|
||||||
|
### Exchange
|
||||||
|
|
||||||
|
???
|
||||||
|
|
||||||
|
### Time Frame
|
||||||
|
|
||||||
|
???min
|
||||||
|
|
||||||
|
### Start Date
|
||||||
|
|
||||||
|
14 may 2023 | 07:25 UTC
|
||||||
|
|
||||||
|
### End Date
|
||||||
|
|
||||||
|
22 may 2023 | 08:55 UTC
|
||||||
|
|
||||||
|
### Risk to Reward
|
||||||
|
|
||||||
|
1:1.5
|
||||||
|
|
||||||
|
### Reports
|
||||||
|
|
||||||
|
#### Longs
|
||||||
|
|
||||||
|
| ID | Position Type | TP | SL | Description |
|
||||||
|
| :--: | :-----------: | :--: | :--: | :---------- |
|
||||||
|
| 1 | Long | | | |
|
||||||
|
| 2 | Long | | | |
|
||||||
|
| 3 | Long | | | |
|
||||||
|
| 4 | Long | | | |
|
||||||
|
| 5 | Long | | | |
|
||||||
|
| 6 | Long | | | |
|
||||||
|
| 7 | Long | | | |
|
||||||
|
| 8 | Long | | | |
|
||||||
|
| 9 | Long | | | |
|
||||||
|
| 10 | Long | | | |
|
||||||
|
| 11 | Long | | | |
|
||||||
|
| 12 | Long | | | |
|
||||||
|
| 13 | Long | | | |
|
||||||
|
| 14 | Long | | | |
|
||||||
|
| 15 | Long | | | |
|
||||||
|
| 16 | Long | | | |
|
||||||
|
| 17 | Long | | | |
|
||||||
|
| 18 | Long | | | |
|
||||||
|
| 19 | Long | | | |
|
||||||
|
| 20 | Long | | | |
|
||||||
|
|
||||||
|
#### Shorts
|
||||||
|
|
||||||
|
| ID | Position Type | TP | SL | Description |
|
||||||
|
| :--: | :-----------: | :--: | :--: | :---------- |
|
||||||
|
| 1 | Short | | | |
|
||||||
|
| 2 | Short | | | |
|
||||||
|
| 3 | Short | | | |
|
||||||
|
| 4 | Short | | | |
|
||||||
|
| 5 | Short | | | |
|
||||||
|
| 6 | Short | | | |
|
||||||
|
| 7 | Short | | | |
|
||||||
|
| 8 | Short | | | |
|
||||||
|
| 9 | Short | | | |
|
||||||
|
| 10 | Short | | | |
|
||||||
|
| 11 | Short | | | |
|
||||||
|
| 12 | Short | | | |
|
||||||
|
| 13 | Short | | | |
|
||||||
|
| 14 | Short | | | |
|
||||||
|
| 15 | Short | | | |
|
||||||
|
| 16 | Short | | | |
|
||||||
|
| 17 | Short | | | |
|
||||||
|
| 18 | Short | | | |
|
||||||
|
| 19 | Short | | | |
|
||||||
|
| 20 | Short | | | |
|
||||||
|
|
||||||
|
#### Signals Results
|
||||||
|
|
||||||
|
| Type | Count | TPs | SLs |
|
||||||
|
| :----: | :-: | :-: | :-: |
|
||||||
|
| Longs | 00 | 00 | 00 |
|
||||||
|
| Shorts | 00 | 00 | 00 |
|
||||||
|
| Total | 00 | 00 | 00 |
|
||||||
|
|
||||||
|
#### Analysis
|
||||||
|
|
||||||
|
per trade volume: 10$
|
||||||
|
total drawdown: 200$
|
||||||
|
total lose: $
|
||||||
|
total reward: $
|
||||||
|
total cash: $
|
||||||
|
win rate: %
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# ????
|
||||||
|
|
||||||
|
## Makret
|
||||||
|
|
||||||
|
## Exchange
|
||||||
|
|
||||||
|
## Time Frame
|
||||||
|
|
||||||
|
## Start Date
|
||||||
|
|
||||||
|
## End Date
|
||||||
|
|
||||||
|
## Reports
|
||||||
|
|
||||||
|
| ID | Position Type | TP | SL | Description |
|
||||||
|
| -- | ------------- | -- | -- | ----------- |
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
//
|
||||||
|
// Check if a Candle is Bullish based on CRT Indicator ...
|
||||||
|
bool isBullishCRT(X_CANDLE_TYPE type) {
|
||||||
|
//
|
||||||
|
switch(type) {
|
||||||
|
//
|
||||||
|
case X_CT_HAMMER:
|
||||||
|
case X_CT_BULLISH_BELT:
|
||||||
|
case X_CT_MORNING_STAR:
|
||||||
|
case X_CT_BULLISH_KICKER:
|
||||||
|
case X_CT_BULLISH_HARAMI:
|
||||||
|
case X_CT_INVERTED_HAMMER:
|
||||||
|
case X_CT_BULLISH_ENGULFING:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Check if a Candle is Bearish based on CRT Indicator ...
|
||||||
|
bool isBearishCRT(X_CANDLE_TYPE type) {
|
||||||
|
//
|
||||||
|
switch(type) {
|
||||||
|
//
|
||||||
|
case X_CT_PRICE_LINE:
|
||||||
|
case X_CT_HANGING_MAN:
|
||||||
|
case X_CT_EVENING_STAR:
|
||||||
|
case X_CT_SHOOTING_STAR:
|
||||||
|
case X_CT_BEARISH_HARAMI:
|
||||||
|
case X_CT_BEARISH_KICKER:
|
||||||
|
case X_CT_DARK_CLOUD_COVER:
|
||||||
|
case X_CT_BEARISH_ENGULFING:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center ??? Strategy Expert Advisor
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of strategy expert advisor ...
|
||||||
|
//
|
||||||
|
// ShortName: ???
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm ??? Strategy Expert Advisor"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Ticker Event Handler ...
|
||||||
|
void OnTick()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center ??? Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above indicator ...
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm ??? Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
#property indicator_chart_window
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Initialize what we want ...
|
||||||
|
|
||||||
|
//
|
||||||
|
return(INIT_SUCCEEDED);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated,
|
||||||
|
const datetime &time[],
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &low[],
|
||||||
|
const double &close[],
|
||||||
|
const long &tick_volume[],
|
||||||
|
const long &volume[],
|
||||||
|
const int &spread[]
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// this counts Available Bars ...
|
||||||
|
int limit;
|
||||||
|
|
||||||
|
//
|
||||||
|
// because in some cases we may have more than one input for
|
||||||
|
// calculation and we must prevent any calculation
|
||||||
|
// untill we pass the biggest input length, here we get max Input length
|
||||||
|
// and then wait until pass it ...
|
||||||
|
int maxLength = MathMax(0, 0);
|
||||||
|
|
||||||
|
//
|
||||||
|
// input variable, we return 0 means nothing passed ...
|
||||||
|
if (rates_total < maxLength) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// found which candles calculated before ...
|
||||||
|
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is the main loop of calculations, for each bar index ...
|
||||||
|
for (int i = limit - 1; i >= 0; i--) {
|
||||||
|
//
|
||||||
|
// Start Calculation here ...
|
||||||
|
// i is bar_index ...
|
||||||
|
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center Library
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of strategy expert advisor ...
|
||||||
|
//
|
||||||
|
// ShortName: ???
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
#property library
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://www.saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center ??? Oscillator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above oscillator ...
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm ??? Oscillator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Initialize what we want ...
|
||||||
|
|
||||||
|
//
|
||||||
|
return(INIT_SUCCEEDED);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center ??? Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above indicator ...
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//
|
||||||
|
//@version=5
|
||||||
|
indicator(title="SaherElm ??? Indicator", shorttitle = "XS_??_IND", overlay = true)
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ....
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Inputs ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ....
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Functions ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Calculations ....
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Calculations ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Plots ....
|
||||||
|
//
|
||||||
|
plot(close)
|
||||||
|
//
|
||||||
|
// END Plots ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Alerts ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Alerts ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
// TODOS:
|
||||||
|
// -------
|
||||||
|
// - []
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center ??? Oscillator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above oscillator ...
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//
|
||||||
|
//@version=5
|
||||||
|
indicator(title="SaherElm ??? Oscillator", shorttitle = "XS_??_OSC", overlay = false)
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ....
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Inputs ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ....
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Functions ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Calculations ....
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Calculations ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Plots ....
|
||||||
|
//
|
||||||
|
plot(close)
|
||||||
|
//
|
||||||
|
// END Plots ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Alerts ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// END Alerts ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
// TODOS:
|
||||||
|
// -------
|
||||||
|
// - []
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center XTrade ??? Strategy
|
||||||
|
// ---------------------------------------------
|
||||||
|
// in this strategy i must use:
|
||||||
|
// - ;
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//
|
||||||
|
//@version=5
|
||||||
|
indicator(title="SaherElm XTrade ??? Strategy", shorttitle = "XST_???", overlay = true)
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ....
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Determines Show Signals or not ...
|
||||||
|
showSignals = input.bool(defval = true, title = "Show Signals", group = "Strategy")
|
||||||
|
showStopLosses = input.bool(defval = true, title = "Show Stop Losses", group = "Strategy")
|
||||||
|
|
||||||
|
//
|
||||||
|
// Show Signals based on their types ...
|
||||||
|
showLongSignals = input.bool(defval = true, title = "Show Long Signals", group = "Signals")
|
||||||
|
showShortSignals = input.bool(defval = true, title = "Show Short Signals", group = "Signals")
|
||||||
|
|
||||||
|
//
|
||||||
|
// Show Stop Losses based on their types ...
|
||||||
|
swingLoopback = input.int(defval = 7, title = "Swing Loopback Period", group = "Stop Loss")
|
||||||
|
showLongStopLosses = input.bool(defval = true, title = "Show Long Stop Losses", group = "Stop Loss")
|
||||||
|
showShortStopLosses = input.bool(defval = true, title = "Show Short Stop Losses", group = "Stop Loss")
|
||||||
|
//
|
||||||
|
// END Inputs ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ....
|
||||||
|
//
|
||||||
|
//////////////////////////////
|
||||||
|
// START Price Action Candles
|
||||||
|
//////////////////////////////
|
||||||
|
//
|
||||||
|
// Retrieve Specific Candle Height (based on low and high) ...
|
||||||
|
getCandleRange() =>
|
||||||
|
high - low
|
||||||
|
|
||||||
|
//
|
||||||
|
// Retrieve Candle Ranges Thirs Section ...
|
||||||
|
getCandleThird() =>
|
||||||
|
getCandleRange() / 3
|
||||||
|
|
||||||
|
//
|
||||||
|
// Determines a Candle is Bullish or not ...
|
||||||
|
isBullishCandle() =>
|
||||||
|
close > low + (getCandleThird() * 2)
|
||||||
|
|
||||||
|
//
|
||||||
|
// Determines a Candle is Bearish or not ...
|
||||||
|
isNeutralCandle() =>
|
||||||
|
close < low + (getCandleThird() * 2) and close > low + getCandleThird()
|
||||||
|
|
||||||
|
//
|
||||||
|
// Determines a Candle is Neutral or not ...
|
||||||
|
isBearishCandle() =>
|
||||||
|
close < low + getCandleThird()
|
||||||
|
/////////////////////////////
|
||||||
|
// END Price Action Candles
|
||||||
|
/////////////////////////////
|
||||||
|
//
|
||||||
|
// END Functions ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Calculations ....
|
||||||
|
//
|
||||||
|
//
|
||||||
|
var shortColor = color.red
|
||||||
|
var longColor = color.lime
|
||||||
|
|
||||||
|
//////////////////////////////
|
||||||
|
// START Price Action Candles
|
||||||
|
//////////////////////////////
|
||||||
|
//
|
||||||
|
var bullishColor = color.lime
|
||||||
|
var bullishShape = shape.arrowup
|
||||||
|
var bullishTitle = "Bullish"
|
||||||
|
var bullishType = 1
|
||||||
|
|
||||||
|
//
|
||||||
|
var bearishColor = color.red
|
||||||
|
var bearishShape = shape.arrowdown
|
||||||
|
var bearishTitle = "Bearish"
|
||||||
|
var bearishType = -1
|
||||||
|
|
||||||
|
//
|
||||||
|
var neutralColor = color.gray
|
||||||
|
var neutralShape = shape.circle
|
||||||
|
var neutralTitle = "Neutral"
|
||||||
|
var neutralType = 0
|
||||||
|
|
||||||
|
//
|
||||||
|
candleType = isBullishCandle() ? bullishType : isNeutralCandle() ? neutralType : isBearishCandle() ? bearishType : neutralType
|
||||||
|
|
||||||
|
//
|
||||||
|
prevCandleType = not na(candleType[1]) ? candleType[1] : neutralType
|
||||||
|
|
||||||
|
//
|
||||||
|
candleNeighborhoodBaseType = prevCandleType + candleType
|
||||||
|
/////////////////////////////
|
||||||
|
// END Price Action Candles
|
||||||
|
/////////////////////////////
|
||||||
|
|
||||||
|
////////////////////////////
|
||||||
|
// START Last Market Price
|
||||||
|
////////////////////////////
|
||||||
|
//
|
||||||
|
lastMarketLowest = ta.lowest(low, swingLoopback)
|
||||||
|
lastMarketLowest2 = ta.lowest(low, swingLoopback * 2)
|
||||||
|
lastMarketLowest3 = ta.lowest(low, swingLoopback * 3)
|
||||||
|
|
||||||
|
//
|
||||||
|
lastMarketHighest = ta.highest(high, swingLoopback)
|
||||||
|
lastMarketHighest2 = ta.highest(high, swingLoopback * 2)
|
||||||
|
lastMarketHighest3 = ta.highest(high, swingLoopback * 3)
|
||||||
|
////////////////////////////
|
||||||
|
// END Last Market Price
|
||||||
|
////////////////////////////
|
||||||
|
|
||||||
|
///////////////////////
|
||||||
|
// START Strategy ...
|
||||||
|
///////////////////////
|
||||||
|
//
|
||||||
|
canShowStopLoss = showSignals and showStopLosses and (showLongSignals or showShortSignals) and (showLongStopLosses or showShortStopLosses)
|
||||||
|
canShowLongStopLoss = canShowStopLoss and showLongStopLosses // and not na(ATRSLLongStopLoss)
|
||||||
|
canShowShortStopLoss = canShowStopLoss and showShortStopLosses // and not na(ATRSLShortStopLoss)
|
||||||
|
|
||||||
|
//
|
||||||
|
hasSignal = false // HUTRHasSignal
|
||||||
|
|
||||||
|
//
|
||||||
|
hasLongSignal = hasSignal and isBullishCandle() and false // HUTRHasLongSignal
|
||||||
|
longSignal = hasLongSignal ? na : na // HUTRLongSignal : na
|
||||||
|
float longStopLoss = lastMarketLowest
|
||||||
|
|
||||||
|
//
|
||||||
|
hasShortSignal = hasSignal and isBearishCandle() and false // HUTRHasShortSignal
|
||||||
|
shortSignal = hasShortSignal ? na : na // HUTRShortSignal : na
|
||||||
|
float shortStopLoss = lastMarketHighest
|
||||||
|
|
||||||
|
//
|
||||||
|
canShowSignal = showSignals and (showLongSignals or showShortSignals)
|
||||||
|
canShowLongSignal = canShowSignal and showLongSignals and hasLongSignal
|
||||||
|
canShowShortSignal = canShowSignal and showShortSignals and hasShortSignal
|
||||||
|
///////////////////////
|
||||||
|
// END Strategy ...
|
||||||
|
///////////////////////
|
||||||
|
//
|
||||||
|
// END Calculations ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Plots ....
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Signals ...
|
||||||
|
plotshape(canShowLongSignal ? longSignal : na, title = "Long Signal", color = longColor, location = location.belowbar, style = shape.triangleup, size = size.normal)
|
||||||
|
plotshape(canShowShortSignal ? shortSignal : na, title = "Short Signal", color = shortColor, location = location.abovebar, style = shape.triangledown, size = size.normal)
|
||||||
|
|
||||||
|
//
|
||||||
|
// Stop Losses ...
|
||||||
|
plot(series = canShowLongStopLoss ? longStopLoss : na, color = color.fuchsia, linewidth = 1, style = plot.style_stepline, title = "Long Stop Loss")
|
||||||
|
plot(series = canShowShortStopLoss ? shortStopLoss : na, color = color.aqua, linewidth = 1, style = plot.style_stepline, title = "Short Stop Loss")
|
||||||
|
//
|
||||||
|
// END Plots ....
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Alerts ...
|
||||||
|
//
|
||||||
|
alertcondition(hasSignal, "XST_SHULL5M > Signal")
|
||||||
|
alertcondition(hasLongSignal, "XST_SHULL5M > Long Signal")
|
||||||
|
alertcondition(hasShortSignal, "XST_SHULL5M > Short Signal")
|
||||||
|
//
|
||||||
|
// END Alerts ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
// TODOS:
|
||||||
|
// -------
|
||||||
|
// - []
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
Daily Time Frame:
|
||||||
|
------------------
|
||||||
|
|
||||||
|
-------------------------
|
||||||
|
LONGS:
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
XTrade Strong Buy Signals
|
||||||
|
-------------------------
|
||||||
|
R2R => 1 risk to 2 reward
|
||||||
|
|
||||||
|
Signals:
|
||||||
|
---------
|
||||||
|
Found:
|
||||||
|
TP:
|
||||||
|
SL:
|
||||||
|
Open:
|
||||||
|
|
||||||
|
XTrade Buy Signals
|
||||||
|
-------------------
|
||||||
|
R2R => 1 risk to 1.5 reward
|
||||||
|
|
||||||
|
Signals:
|
||||||
|
---------
|
||||||
|
Found:
|
||||||
|
TP:
|
||||||
|
SL:
|
||||||
|
Open:
|
||||||
|
|
||||||
|
|
||||||
|
--------------------------
|
||||||
|
SHORTS:
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
XTrade Strong SELl Signals
|
||||||
|
--------------------------
|
||||||
|
R2R => 1 risk to 2 reward
|
||||||
|
|
||||||
|
Signals:
|
||||||
|
---------
|
||||||
|
Found:
|
||||||
|
TP:
|
||||||
|
SL:
|
||||||
|
Open:
|
||||||
|
|
||||||
|
XTrade Sell Signals
|
||||||
|
--------------------
|
||||||
|
R2R => 1 risk to 1.5 reward
|
||||||
|
|
||||||
|
Signals:
|
||||||
|
---------
|
||||||
|
Found:
|
||||||
|
TP:
|
||||||
|
SL:
|
||||||
|
Open:
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
signalPrefix=XST_EA
|
||||||
|
bullishSignalLabel=X_BUY
|
||||||
|
bullishSignalColor=16776960
|
||||||
|
bearishSignalLabel=X_SELL
|
||||||
|
bearishSignalColor=16711935
|
||||||
|
signalEntryColor=13959039
|
||||||
|
signalSLColor=255
|
||||||
|
signalTPColor=32768
|
||||||
|
candleGapBetweenSignals=7
|
||||||
|
candleGapBetweenSignals,F=0
|
||||||
|
candleGapBetweenSignals,1=6
|
||||||
|
candleGapBetweenSignals,2=0
|
||||||
|
candleGapBetweenSignals,3=0
|
||||||
|
allowTrade=1
|
||||||
|
allowTrade,F=0
|
||||||
|
allowTrade,1=0
|
||||||
|
allowTrade,2=1
|
||||||
|
allowTrade,3=1
|
||||||
|
allowLongTrades=1
|
||||||
|
allowLongTrades,F=0
|
||||||
|
allowLongTrades,1=0
|
||||||
|
allowLongTrades,2=1
|
||||||
|
allowLongTrades,3=1
|
||||||
|
allowShortTrades=1
|
||||||
|
allowShortTrades,F=0
|
||||||
|
allowShortTrades,1=0
|
||||||
|
allowShortTrades,2=1
|
||||||
|
allowShortTrades,3=1
|
||||||
|
alertEvents=1
|
||||||
|
alertEvents,F=0
|
||||||
|
alertEvents,1=0
|
||||||
|
alertEvents,2=1
|
||||||
|
alertEvents,3=1
|
||||||
|
alertPositions=1
|
||||||
|
alertPositions,F=0
|
||||||
|
alertPositions,1=0
|
||||||
|
alertPositions,2=1
|
||||||
|
alertPositions,3=1
|
||||||
|
longPositionAlerts=1
|
||||||
|
longPositionAlerts,F=0
|
||||||
|
longPositionAlerts,1=0
|
||||||
|
longPositionAlerts,2=1
|
||||||
|
longPositionAlerts,3=1
|
||||||
|
shortPositionAlerts=1
|
||||||
|
shortPositionAlerts,F=0
|
||||||
|
shortPositionAlerts,1=0
|
||||||
|
shortPositionAlerts,2=1
|
||||||
|
shortPositionAlerts,3=1
|
||||||
|
terminalAlert=0
|
||||||
|
terminalAlert,F=0
|
||||||
|
terminalAlert,1=0
|
||||||
|
terminalAlert,2=1
|
||||||
|
terminalAlert,3=1
|
||||||
|
pushAlert=0
|
||||||
|
pushAlert,F=0
|
||||||
|
pushAlert,1=0
|
||||||
|
pushAlert,2=1
|
||||||
|
pushAlert,3=1
|
||||||
|
lotsPerTradePercent=0.00001000
|
||||||
|
lotsPerTradePercent,F=0
|
||||||
|
lotsPerTradePercent,1=0.00030000
|
||||||
|
lotsPerTradePercent,2=0.00000000
|
||||||
|
lotsPerTradePercent,3=0.00000000
|
||||||
|
maxOpenTrades=4
|
||||||
|
maxOpenTrades,F=0
|
||||||
|
maxOpenTrades,1=4
|
||||||
|
maxOpenTrades,2=0
|
||||||
|
maxOpenTrades,3=0
|
||||||
|
maxDrawdownPercentPerPTrade=0.10000000
|
||||||
|
maxDrawdownPercentPerPTrade,F=0
|
||||||
|
maxDrawdownPercentPerPTrade,1=0.30000000
|
||||||
|
maxDrawdownPercentPerPTrade,2=0.00000000
|
||||||
|
maxDrawdownPercentPerPTrade,3=0.00000000
|
||||||
|
minBalancePercent=0.50000000
|
||||||
|
minBalancePercent,F=0
|
||||||
|
minBalancePercent,1=0.50000000
|
||||||
|
minBalancePercent,2=0.00000000
|
||||||
|
minBalancePercent,3=0.00000000
|
||||||
|
maxEquityPercent=0.10000000
|
||||||
|
maxEquityPercent,F=0
|
||||||
|
maxEquityPercent,1=0.10000000
|
||||||
|
maxEquityPercent,2=0.00000000
|
||||||
|
maxEquityPercent,3=0.00000000
|
||||||
|
xStarter=- X Signal Provider -
|
||||||
|
enableXSignalling=1
|
||||||
|
enableXSignalling,F=0
|
||||||
|
enableXSignalling,1=0
|
||||||
|
enableXSignalling,2=1
|
||||||
|
enableXSignalling,3=1
|
||||||
|
enableXLong=1
|
||||||
|
enableXLong,F=0
|
||||||
|
enableXLong,1=0
|
||||||
|
enableXLong,2=1
|
||||||
|
enableXLong,3=1
|
||||||
|
enableXShort=1
|
||||||
|
enableXShort,F=0
|
||||||
|
enableXShort,1=0
|
||||||
|
enableXShort,2=1
|
||||||
|
enableXShort,3=1
|
||||||
|
xShortR2R=3.00000000
|
||||||
|
xShortR2R,F=0
|
||||||
|
xShortR2R,1=2.50000000
|
||||||
|
xShortR2R,2=0.00000000
|
||||||
|
xShortR2R,3=0.00000000
|
||||||
|
xShortLotsPerTradePercent=0.00025000
|
||||||
|
xShortLotsPerTradePercent,F=0
|
||||||
|
xShortLotsPerTradePercent,1=0.00002000
|
||||||
|
xShortLotsPerTradePercent,2=0.00000000
|
||||||
|
xShortLotsPerTradePercent,3=0.00000000
|
||||||
|
xShortMaxDrawdownPerTradePercent=0.45000000
|
||||||
|
xShortMaxDrawdownPerTradePercent,F=0
|
||||||
|
xShortMaxDrawdownPerTradePercent,1=0.02000000
|
||||||
|
xShortMaxDrawdownPerTradePercent,2=0.00000000
|
||||||
|
xShortMaxDrawdownPerTradePercent,3=0.00000000
|
||||||
|
xLongR2R=3.00000000
|
||||||
|
xLongR2R,F=0
|
||||||
|
xLongR2R,1=2.50000000
|
||||||
|
xLongR2R,2=0.00000000
|
||||||
|
xLongR2R,3=0.00000000
|
||||||
|
xLongLotsPerTradePercent=0.00025000
|
||||||
|
xLongLotsPerTradePercent,F=0
|
||||||
|
xLongLotsPerTradePercent,1=0.00002000
|
||||||
|
xLongLotsPerTradePercent,2=0.00000000
|
||||||
|
xLongLotsPerTradePercent,3=0.00000000
|
||||||
|
xLongMaxDrawdownPerTradePercent=0.45000000
|
||||||
|
xLongMaxDrawdownPerTradePercent,F=0
|
||||||
|
xLongMaxDrawdownPerTradePercent,1=0.02000000
|
||||||
|
xLongMaxDrawdownPerTradePercent,2=0.00000000
|
||||||
|
xLongMaxDrawdownPerTradePercent,3=0.00000000
|
||||||
|
xSharpDetectorFactor=700.00000000
|
||||||
|
xSharpDetectorFactor,F=0
|
||||||
|
xSharpDetectorFactor,1=700.00000000
|
||||||
|
xSharpDetectorFactor,2=0.00000000
|
||||||
|
xSharpDetectorFactor,3=0.00000000
|
||||||
|
xMaximumCandlesPerTrade=206
|
||||||
|
xMaximumCandlesPerTrade,F=0
|
||||||
|
xMaximumCandlesPerTrade,1=504
|
||||||
|
xMaximumCandlesPerTrade,2=0
|
||||||
|
xMaximumCandlesPerTrade,3=0
|
||||||
|
xOscillatorLength=7
|
||||||
|
xOscillatorLength,F=0
|
||||||
|
xOscillatorLength,1=7
|
||||||
|
xOscillatorLength,2=0
|
||||||
|
xOscillatorLength,3=0
|
||||||
|
xPSarStep=0.02000000
|
||||||
|
xPSarStep,F=0
|
||||||
|
xPSarStep,1=0.02000000
|
||||||
|
xPSarStep,2=0.00000000
|
||||||
|
xPSarStep,3=0.00000000
|
||||||
|
xPSarMaximum=0.20000000
|
||||||
|
xPSarMaximum,F=0
|
||||||
|
xPSarMaximum,1=0.20000000
|
||||||
|
xPSarMaximum,2=0.00000000
|
||||||
|
xPSarMaximum,3=0.00000000
|
||||||
|
xRangeMarketLength=5
|
||||||
|
xRangeMarketLength,F=0
|
||||||
|
xRangeMarketLength,1=35
|
||||||
|
xRangeMarketLength,2=0
|
||||||
|
xRangeMarketLength,3=0
|
||||||
|
xSwingLength=7
|
||||||
|
xSwingLength,F=0
|
||||||
|
xSwingLength,1=7
|
||||||
|
xSwingLength,2=0
|
||||||
|
xSwingLength,3=0
|
||||||
|
xRStarter=- XR Signal Provider -
|
||||||
|
enableXRSignalling=0
|
||||||
|
enableXRSignalling,F=0
|
||||||
|
enableXRSignalling,1=0
|
||||||
|
enableXRSignalling,2=1
|
||||||
|
enableXRSignalling,3=1
|
||||||
|
enableXRLong=1
|
||||||
|
enableXRLong,F=0
|
||||||
|
enableXRLong,1=0
|
||||||
|
enableXRLong,2=1
|
||||||
|
enableXRLong,3=1
|
||||||
|
enableXRShort=1
|
||||||
|
enableXRShort,F=0
|
||||||
|
enableXRShort,1=0
|
||||||
|
enableXRShort,2=1
|
||||||
|
enableXRShort,3=1
|
||||||
|
xRShortR2R=1.50000000
|
||||||
|
xRShortR2R,F=0
|
||||||
|
xRShortR2R,1=2.00000000
|
||||||
|
xRShortR2R,2=0.00000000
|
||||||
|
xRShortR2R,3=0.00000000
|
||||||
|
xRShortLotsPerTradePercent=0.00020000
|
||||||
|
xRShortLotsPerTradePercent,F=0
|
||||||
|
xRShortLotsPerTradePercent,1=0.00001000
|
||||||
|
xRShortLotsPerTradePercent,2=0.00000000
|
||||||
|
xRShortLotsPerTradePercent,3=0.00000000
|
||||||
|
xRShortMaxDrawdownPerTradePercent=0.15000000
|
||||||
|
xRShortMaxDrawdownPerTradePercent,F=0
|
||||||
|
xRShortMaxDrawdownPerTradePercent,1=0.01000000
|
||||||
|
xRShortMaxDrawdownPerTradePercent,2=0.00000000
|
||||||
|
xRShortMaxDrawdownPerTradePercent,3=0.00000000
|
||||||
|
xRLongR2R=1.50000000
|
||||||
|
xRLongR2R,F=0
|
||||||
|
xRLongR2R,1=2.00000000
|
||||||
|
xRLongR2R,2=0.00000000
|
||||||
|
xRLongR2R,3=0.00000000
|
||||||
|
xRLongLotsPerTradePercent=0.00020000
|
||||||
|
xRLongLotsPerTradePercent,F=0
|
||||||
|
xRLongLotsPerTradePercent,1=0.00001000
|
||||||
|
xRLongLotsPerTradePercent,2=0.00000000
|
||||||
|
xRLongLotsPerTradePercent,3=0.00000000
|
||||||
|
xRLongMaxDrawdownPerTradePercent=0.15000000
|
||||||
|
xRLongMaxDrawdownPerTradePercent,F=0
|
||||||
|
xRLongMaxDrawdownPerTradePercent,1=0.01000000
|
||||||
|
xRLongMaxDrawdownPerTradePercent,2=0.00000000
|
||||||
|
xRLongMaxDrawdownPerTradePercent,3=0.00000000
|
||||||
|
xRMaximumCandlesPerTrade=96
|
||||||
|
xRMaximumCandlesPerTrade,F=0
|
||||||
|
xRMaximumCandlesPerTrade,1=252
|
||||||
|
xRMaximumCandlesPerTrade,2=0
|
||||||
|
xRMaximumCandlesPerTrade,3=0
|
||||||
|
xRSwingLength=48
|
||||||
|
xRSwingLength,F=0
|
||||||
|
xRSwingLength,1=7
|
||||||
|
xRSwingLength,2=0
|
||||||
|
xRSwingLength,3=0
|
||||||
|
xRSharpDetectionFactor=1350.00000000
|
||||||
|
xRSharpDetectionFactor,F=0
|
||||||
|
xRSharpDetectionFactor,1=650.00000000
|
||||||
|
xRSharpDetectionFactor,2=0.00000000
|
||||||
|
xRSharpDetectionFactor,3=0.00000000
|
||||||
|
xTPWStarter=- XTPW Signal Provider -
|
||||||
|
enableXTPWSignalling=1
|
||||||
|
enableXTPWSignalling,F=0
|
||||||
|
enableXTPWSignalling,1=0
|
||||||
|
enableXTPWSignalling,2=1
|
||||||
|
enableXTPWSignalling,3=1
|
||||||
|
enableXTPWLong=1
|
||||||
|
enableXTPWLong,F=0
|
||||||
|
enableXTPWLong,1=0
|
||||||
|
enableXTPWLong,2=1
|
||||||
|
enableXTPWLong,3=1
|
||||||
|
enableXTPWShort=1
|
||||||
|
enableXTPWShort,F=0
|
||||||
|
enableXTPWShort,1=0
|
||||||
|
enableXTPWShort,2=1
|
||||||
|
enableXTPWShort,3=1
|
||||||
|
xTPWShortR2R=2.00000000
|
||||||
|
xTPWShortR2R,F=0
|
||||||
|
xTPWShortR2R,1=1.50000000
|
||||||
|
xTPWShortR2R,2=0.00000000
|
||||||
|
xTPWShortR2R,3=0.00000000
|
||||||
|
xTPWShortLotsPerTradePercent=0.00025000
|
||||||
|
xTPWShortLotsPerTradePercent,F=0
|
||||||
|
xTPWShortLotsPerTradePercent,1=0.00001000
|
||||||
|
xTPWShortLotsPerTradePercent,2=0.00000000
|
||||||
|
xTPWShortLotsPerTradePercent,3=0.00000000
|
||||||
|
xTPWShortMaxDrawdownPerTradePercent=0.30000000
|
||||||
|
xTPWShortMaxDrawdownPerTradePercent,F=0
|
||||||
|
xTPWShortMaxDrawdownPerTradePercent,1=0.01000000
|
||||||
|
xTPWShortMaxDrawdownPerTradePercent,2=0.00000000
|
||||||
|
xTPWShortMaxDrawdownPerTradePercent,3=0.00000000
|
||||||
|
xTPWLongR2R=2.00000000
|
||||||
|
xTPWLongR2R,F=0
|
||||||
|
xTPWLongR2R,1=1.50000000
|
||||||
|
xTPWLongR2R,2=0.00000000
|
||||||
|
xTPWLongR2R,3=0.00000000
|
||||||
|
xTPWLongLotsPerTradePercent=0.00025000
|
||||||
|
xTPWLongLotsPerTradePercent,F=0
|
||||||
|
xTPWLongLotsPerTradePercent,1=0.00001000
|
||||||
|
xTPWLongLotsPerTradePercent,2=0.00000000
|
||||||
|
xTPWLongLotsPerTradePercent,3=0.00000000
|
||||||
|
xTPWLongMaxDrawdownPerTradePercent=0.30000000
|
||||||
|
xTPWLongMaxDrawdownPerTradePercent,F=0
|
||||||
|
xTPWLongMaxDrawdownPerTradePercent,1=0.01000000
|
||||||
|
xTPWLongMaxDrawdownPerTradePercent,2=0.00000000
|
||||||
|
xTPWLongMaxDrawdownPerTradePercent,3=0.00000000
|
||||||
|
xTPWMaximumCandlesPerTrade=206
|
||||||
|
xTPWMaximumCandlesPerTrade,F=0
|
||||||
|
xTPWMaximumCandlesPerTrade,1=206
|
||||||
|
xTPWMaximumCandlesPerTrade,2=0
|
||||||
|
xTPWMaximumCandlesPerTrade,3=0
|
||||||
|
xTPWPSarStep=0.02000000
|
||||||
|
xTPWPSarStep,F=0
|
||||||
|
xTPWPSarStep,1=0.02000000
|
||||||
|
xTPWPSarStep,2=0.00000000
|
||||||
|
xTPWPSarStep,3=0.00000000
|
||||||
|
xTPWPSarMaximum=0.20000000
|
||||||
|
xTPWPSarMaximum,F=0
|
||||||
|
xTPWPSarMaximum,1=0.20000000
|
||||||
|
xTPWPSarMaximum,2=0.00000000
|
||||||
|
xTPWPSarMaximum,3=0.00000000
|
||||||
|
xTPWSwingLength=7
|
||||||
|
xTPWSwingLength,F=0
|
||||||
|
xTPWSwingLength,1=7
|
||||||
|
xTPWSwingLength,2=0
|
||||||
|
xTPWSwingLength,3=0
|
||||||
|
xTPWSharpDetectionFactor=650.00000000
|
||||||
|
xTPWSharpDetectionFactor,F=0
|
||||||
|
xTPWSharpDetectionFactor,1=700.00000000
|
||||||
|
xTPWSharpDetectionFactor,2=0.00000000
|
||||||
|
xTPWSharpDetectionFactor,3=0.00000000
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,173 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MA Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above indicator ...
|
||||||
|
// this indicator uses two ma line:
|
||||||
|
// - fast ma;
|
||||||
|
// - slow ma;
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm MA Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Fast MA ...
|
||||||
|
input int maLength = 20; // MA Length
|
||||||
|
input int maShift = 0; // MA Shift
|
||||||
|
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Method
|
||||||
|
input ENUM_APPLIED_PRICE maAppliedPrice = PRICE_CLOSE; // MA Applied Price
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
#property indicator_chart_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_plots 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Fast Ma Buffer ...
|
||||||
|
#property indicator_label1 "Ma"
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrYellow
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
#property indicator_width1 2
|
||||||
|
|
||||||
|
//
|
||||||
|
// End Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
#define maBufferIndex 0
|
||||||
|
|
||||||
|
double maBuffer[];
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Initialize what we want ...
|
||||||
|
if (maLength <= 0) {
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Set Index Buffers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Ma ...
|
||||||
|
SetIndexBuffer(maBufferIndex, maBuffer);
|
||||||
|
SetIndexDrawBegin(maBufferIndex, maLength + 1);
|
||||||
|
//
|
||||||
|
// End Set Index Buffers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated,
|
||||||
|
const datetime &time[],
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &low[],
|
||||||
|
const double &close[],
|
||||||
|
const long &tick_volume[],
|
||||||
|
const long &volume[],
|
||||||
|
const int &spread[]
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// this counts Available Bars ...
|
||||||
|
int limit;
|
||||||
|
|
||||||
|
//
|
||||||
|
// because in some cases we may have more than one input for
|
||||||
|
// calculation and we must prevent any calculation
|
||||||
|
// untill we pass the biggest input length, here we get max Input length
|
||||||
|
// and then wait until pass it ...
|
||||||
|
int maxLength = MathMax(0, maLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
// input variable, we return 0 means nothing passed ...
|
||||||
|
if (rates_total < maxLength) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// found which candles calculated before ...
|
||||||
|
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is the main loop of calculations, for each bar index ...
|
||||||
|
for (int i = limit - 1; i >= 0; i--) {
|
||||||
|
//
|
||||||
|
// Start Calculation here ...
|
||||||
|
// i is bar_index ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Ma ...
|
||||||
|
CalculateMa(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Calculating Ma ...
|
||||||
|
void CalculateMa(
|
||||||
|
const int &bar_index
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// Calculating Fast Ma ...
|
||||||
|
double ma = iMA(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
maLength,
|
||||||
|
maShift,
|
||||||
|
maMethod,
|
||||||
|
maAppliedPrice,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
maBuffer[bar_index] = ma;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,294 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center XRange Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above indicator ...
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm XRange Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input int marketLength = 14;
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
#property indicator_chart_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_buffers 3
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_plots 3
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Highest High Buffer ...
|
||||||
|
#property indicator_type1 DRAW_LINE
|
||||||
|
#property indicator_color1 clrGreen
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lowest Low Buffer ...
|
||||||
|
#property indicator_type2 DRAW_LINE
|
||||||
|
#property indicator_color2 clrRed
|
||||||
|
#property indicator_style2 STYLE_DOT
|
||||||
|
#property indicator_width2 1
|
||||||
|
|
||||||
|
//
|
||||||
|
// Middle Buffer ...
|
||||||
|
#property indicator_type3 DRAW_LINE
|
||||||
|
#property indicator_color3 clrYellow
|
||||||
|
#property indicator_style3 STYLE_DASH
|
||||||
|
#property indicator_width3 1
|
||||||
|
//
|
||||||
|
// End Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
//
|
||||||
|
#define highestHighBufferIndex 0
|
||||||
|
#define lowestLowBufferIndex 1
|
||||||
|
#define middleBufferIndex 2
|
||||||
|
|
||||||
|
//
|
||||||
|
double highestHighBuffer[];
|
||||||
|
double lowestLowBuffer[];
|
||||||
|
double middleBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime startTime;
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Initialize what we want ...
|
||||||
|
if (
|
||||||
|
marketLength <= 0
|
||||||
|
) {
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
string hhLbl = StringConcatenate(
|
||||||
|
"XR HH(", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexBuffer(highestHighBufferIndex, highestHighBuffer);
|
||||||
|
SetIndexLabel(highestHighBufferIndex, hhLbl);
|
||||||
|
|
||||||
|
//
|
||||||
|
string llLbl = StringConcatenate(
|
||||||
|
"XR LL(", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexBuffer(lowestLowBufferIndex, lowestLowBuffer);
|
||||||
|
SetIndexLabel(lowestLowBufferIndex, llLbl);
|
||||||
|
|
||||||
|
//
|
||||||
|
string midLbl = StringConcatenate(
|
||||||
|
"XR Mid(", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexBuffer(middleBufferIndex, middleBuffer);
|
||||||
|
SetIndexLabel(middleBufferIndex, midLbl);
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated,
|
||||||
|
const datetime &time[],
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &low[],
|
||||||
|
const double &close[],
|
||||||
|
const long &tick_volume[],
|
||||||
|
const long &volume[],
|
||||||
|
const int &spread[]
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// this counts Available Bars ...
|
||||||
|
int limit;
|
||||||
|
|
||||||
|
//
|
||||||
|
// because in some cases we may have more than one input for
|
||||||
|
// calculation and we must prevent any calculation
|
||||||
|
// untill we pass the biggest input length, here we get max Input length
|
||||||
|
// and then wait until pass it ...
|
||||||
|
int maxLength = MathMax(0, marketLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
// input variable, we return 0 means nothing passed ...
|
||||||
|
if (rates_total < maxLength) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// found which candles calculated before ...
|
||||||
|
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is the main loop of calculations, for each bar index ...
|
||||||
|
for (int i = limit - 1; i >= 0; i--) {
|
||||||
|
//
|
||||||
|
// Start Calculation here ...
|
||||||
|
// i is bar_index ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
CalculateBuffers(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Calculations ...
|
||||||
|
void CalculateBuffers(
|
||||||
|
const int &bar_index
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// Retrieve Bar Time ...
|
||||||
|
datetime barTime = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (startTime == 0) {
|
||||||
|
//
|
||||||
|
startTime = barTime;
|
||||||
|
SetIndicatorBuffersNone(bar_index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
int startBarIndex = iBarShift(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
startTime
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
int startDistance = startBarIndex - bar_index;
|
||||||
|
if (startDistance < marketLength) {
|
||||||
|
//
|
||||||
|
SetIndicatorBuffersNone(bar_index);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Highest High ...
|
||||||
|
int hhIdx = iHighest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
MODE_HIGH,
|
||||||
|
marketLength,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
double hh = iHigh(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
hhIdx
|
||||||
|
);
|
||||||
|
highestHighBuffer[bar_index] = hh;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lowest Low ...
|
||||||
|
int llIdx = iLowest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
MODE_LOW,
|
||||||
|
marketLength,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
double ll = iLow(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
llIdx
|
||||||
|
);
|
||||||
|
lowestLowBuffer[bar_index] = ll;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Middle Buffer ...
|
||||||
|
double mid = (hh + ll) / 2;
|
||||||
|
middleBuffer[bar_index] = mid;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reset Start Time ...
|
||||||
|
startTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
void SetIndicatorBuffersNone(
|
||||||
|
const int bar_index
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
int lastBarIndex = bar_index + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
double lastHighestHigh;
|
||||||
|
double lastLowestLow;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Highest High ...
|
||||||
|
if (ArraySize(highestHighBuffer) > lastBarIndex) {
|
||||||
|
lastHighestHigh = highestHighBuffer[lastBarIndex];
|
||||||
|
} else {
|
||||||
|
lastHighestHigh = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lowest Low ...
|
||||||
|
if (ArraySize(lowestLowBuffer) > lastBarIndex) {
|
||||||
|
lastLowestLow = lowestLowBuffer[lastBarIndex];
|
||||||
|
} else {
|
||||||
|
lastLowestLow = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
highestHighBuffer[bar_index] = lastHighestHigh;
|
||||||
|
lowestLowBuffer[bar_index] = lastLowestLow;
|
||||||
|
|
||||||
|
//
|
||||||
|
double mid = (lastHighestHigh + lastLowestLow) / 2;
|
||||||
|
middleBuffer[bar_index] = mid;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
@@ -0,0 +1,275 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center Trend Power Indicator
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm implementation of above indicator ...
|
||||||
|
// this indicator uses two ma line:
|
||||||
|
// - fast ma;
|
||||||
|
// - slow ma;
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// Global Properties ...
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property description "SaherElm MA Indicator"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Inputs ...
|
||||||
|
//
|
||||||
|
input int marketLength = 7; // Market Length
|
||||||
|
//
|
||||||
|
// END Inputs ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
#property indicator_separate_window
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_plots 3
|
||||||
|
#property indicator_buffers 3
|
||||||
|
#property indicator_minimum 0
|
||||||
|
#property indicator_maximum 100
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_levelcolor clrGray
|
||||||
|
#property indicator_levelstyle STYLE_DOT
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
#property indicator_type1 DRAW_HISTOGRAM
|
||||||
|
#property indicator_color1 clrLime
|
||||||
|
#property indicator_style1 STYLE_DOT
|
||||||
|
#property indicator_width1 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_type2 DRAW_HISTOGRAM
|
||||||
|
#property indicator_color2 clrRed
|
||||||
|
#property indicator_style2 STYLE_DOT
|
||||||
|
#property indicator_width2 1
|
||||||
|
|
||||||
|
//
|
||||||
|
#property indicator_type3 DRAW_LINE
|
||||||
|
#property indicator_color3 clrYellow
|
||||||
|
#property indicator_style3 STYLE_DOT
|
||||||
|
#property indicator_width3 1
|
||||||
|
//
|
||||||
|
// End Define Indicator Buffer Styles ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Buffers ...
|
||||||
|
#define powerUpBufferIndex 0
|
||||||
|
#define powerDownBufferIndex 1
|
||||||
|
#define signalBufferIndex 2
|
||||||
|
|
||||||
|
double powerUpBuffer[];
|
||||||
|
double powerDownBuffer[];
|
||||||
|
double signalBuffer[];
|
||||||
|
|
||||||
|
//
|
||||||
|
#include "../Libraries/x-saherelm.lib.mq4"
|
||||||
|
//
|
||||||
|
// END Global Definitions: Variables, Properties and etc ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Event Handlers ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Initialization ...
|
||||||
|
int OnInit() {
|
||||||
|
//
|
||||||
|
// Initialize what we want ...
|
||||||
|
if (marketLength <= 0) {
|
||||||
|
return INIT_PARAMETERS_INCORRECT;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
SetLevelValue(0, 0.0);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT,0,"");
|
||||||
|
|
||||||
|
//
|
||||||
|
SetLevelValue(1, 20.0);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT,1,"");
|
||||||
|
|
||||||
|
//
|
||||||
|
SetLevelValue(2, 50);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT,2,"");
|
||||||
|
|
||||||
|
//
|
||||||
|
SetLevelValue(3, 100);
|
||||||
|
IndicatorSetString(INDICATOR_LEVELTEXT,3,"");
|
||||||
|
|
||||||
|
//
|
||||||
|
string pUpLbl = StringConcatenate(
|
||||||
|
"P Up (", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexLabel(powerUpBufferIndex, pUpLbl);
|
||||||
|
SetIndexBuffer(powerUpBufferIndex, powerUpBuffer);
|
||||||
|
SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1);
|
||||||
|
|
||||||
|
//
|
||||||
|
string pDownLbl = StringConcatenate(
|
||||||
|
"P Down (", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexLabel(powerDownBufferIndex, pDownLbl);
|
||||||
|
SetIndexBuffer(powerDownBufferIndex, powerDownBuffer);
|
||||||
|
SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1);
|
||||||
|
|
||||||
|
//
|
||||||
|
string pSignalLbl = StringConcatenate(
|
||||||
|
"P Signal (", marketLength, ")"
|
||||||
|
);
|
||||||
|
SetIndexLabel(signalBufferIndex, pSignalLbl);
|
||||||
|
SetIndexBuffer(signalBufferIndex, signalBuffer);
|
||||||
|
SetIndexDrawBegin(signalBufferIndex, marketLength + 1);
|
||||||
|
|
||||||
|
//
|
||||||
|
// here we specify logging enabled or not ...
|
||||||
|
enableLogging = true;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is a Tag which attached to our Logger ...
|
||||||
|
logTag = "X_TPW_OSC";
|
||||||
|
|
||||||
|
//
|
||||||
|
return INIT_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculating what we want ...
|
||||||
|
int OnCalculate(const int rates_total,
|
||||||
|
const int prev_calculated,
|
||||||
|
const datetime &time[],
|
||||||
|
const double &open[],
|
||||||
|
const double &high[],
|
||||||
|
const double &low[],
|
||||||
|
const double &close[],
|
||||||
|
const long &tick_volume[],
|
||||||
|
const long &volume[],
|
||||||
|
const int &spread[]
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
// this counts Available Bars ...
|
||||||
|
int limit;
|
||||||
|
|
||||||
|
//
|
||||||
|
// because in some cases we may have more than one input for
|
||||||
|
// calculation and we must prevent any calculation
|
||||||
|
// untill we pass the biggest input length, here we get max Input length
|
||||||
|
// and then wait until pass it ...
|
||||||
|
int maxLength = MathMax(0, marketLength);
|
||||||
|
|
||||||
|
//
|
||||||
|
// input variable, we return 0 means nothing passed ...
|
||||||
|
if (rates_total < maxLength) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// found which candles calculated before ...
|
||||||
|
limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is the main loop of calculations, for each bar index ...
|
||||||
|
for (int i = limit - 1; i >= 0; i--) {
|
||||||
|
//
|
||||||
|
// Start Calculation here ...
|
||||||
|
// i is bar_index ...
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate Buffers ...
|
||||||
|
CalculateBuffers(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
return rates_total;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Event Handlers ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Calculating Ma ...
|
||||||
|
void CalculateBuffers(
|
||||||
|
const int &bar_index
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
double powerUp = 0;
|
||||||
|
double powerDown = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
int dailyCount = GetDailyCandleCount();
|
||||||
|
double dailyHH = GetMarketHighestHigh(
|
||||||
|
bar_index,
|
||||||
|
dailyCount
|
||||||
|
);
|
||||||
|
double dailyLL = GetMarketLowestLow(
|
||||||
|
bar_index,
|
||||||
|
dailyCount
|
||||||
|
);
|
||||||
|
double dailyDiff = dailyHH - dailyLL;
|
||||||
|
double rate = dailyDiff / 100;
|
||||||
|
|
||||||
|
//
|
||||||
|
for (int i = bar_index; i < bar_index + marketLength; i++) {
|
||||||
|
//
|
||||||
|
XOHCL c = GetCandleModel(i);
|
||||||
|
|
||||||
|
//
|
||||||
|
double cRange =
|
||||||
|
MathAbs(c.open - c.close)
|
||||||
|
// MathAbs(c.high - c.low)
|
||||||
|
;
|
||||||
|
bool isBullish = c.open < c.close;
|
||||||
|
|
||||||
|
//
|
||||||
|
if (isBullish) {
|
||||||
|
powerUp += cRange;
|
||||||
|
} else {
|
||||||
|
powerDown += cRange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
powerUp = powerUp / rate;
|
||||||
|
powerDown = powerDown / rate;
|
||||||
|
|
||||||
|
//
|
||||||
|
int doubleMarketLength = (marketLength * 2);
|
||||||
|
double ema = GetMA(
|
||||||
|
bar_index,
|
||||||
|
doubleMarketLength,
|
||||||
|
0,
|
||||||
|
MODE_EMA,
|
||||||
|
PRICE_WEIGHTED
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100;
|
||||||
|
|
||||||
|
//
|
||||||
|
double signal = (ema / 100) * rate;
|
||||||
|
double signalAddition = MathMin(powerUp, powerDown);
|
||||||
|
|
||||||
|
//
|
||||||
|
powerUpBuffer[bar_index] = powerUp;
|
||||||
|
powerDownBuffer[bar_index] = powerDown;
|
||||||
|
signalBuffer[bar_index] = signal + signalAddition;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Functions ...
|
||||||
|
//
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,450 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL4 Indicator Global Library
|
||||||
|
// ---------------------------------------------------
|
||||||
|
// saherelm useful tools and definitions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
#property library
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://www.saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes library ...
|
||||||
|
#include "../Libraries/x-saherelm.lib.mq4"
|
||||||
|
|
||||||
|
//
|
||||||
|
// Includes Models library ...
|
||||||
|
#include "../Libraries/x-saherelm.models.lib.mq4"
|
||||||
|
|
||||||
|
//
|
||||||
|
// START Global Requirement Functions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Reading specified Buffer From ADX Indicator ...
|
||||||
|
double ReadXMABuffer(
|
||||||
|
const int bar_index,
|
||||||
|
const int buffer_index,
|
||||||
|
//
|
||||||
|
const int marketLen,
|
||||||
|
//
|
||||||
|
const double stp,
|
||||||
|
const double mxm,
|
||||||
|
//
|
||||||
|
const int shortCycleMult,
|
||||||
|
const int mediumCycleMult,
|
||||||
|
const int longCycleMult
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
string xmaIndicatorName = "x-saherelm.x.xma";
|
||||||
|
|
||||||
|
//
|
||||||
|
double result = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
xmaIndicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
stp,
|
||||||
|
mxm,
|
||||||
|
shortCycleMult,
|
||||||
|
mediumCycleMult,
|
||||||
|
longCycleMult,
|
||||||
|
MODE_SMA,
|
||||||
|
//
|
||||||
|
buffer_index,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading specified Buffer from XHL Indicator ...
|
||||||
|
double ReadXHLBuffer(
|
||||||
|
const int bar_index,
|
||||||
|
const int buffer_index,
|
||||||
|
//
|
||||||
|
const int marketLen,
|
||||||
|
//
|
||||||
|
const int shortCycleMult,
|
||||||
|
const int mediumCycleMult,
|
||||||
|
const int longCycleMult
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
string xhlIndicatorName = "x-saherelm.x.hl";
|
||||||
|
|
||||||
|
//
|
||||||
|
double result = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
xhlIndicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
shortCycleMult,
|
||||||
|
mediumCycleMult,
|
||||||
|
longCycleMult,
|
||||||
|
MODE_SMA,
|
||||||
|
//
|
||||||
|
buffer_index,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading ADX Values ...
|
||||||
|
double ReadADX(
|
||||||
|
const int bar_index,
|
||||||
|
const int marketLen,
|
||||||
|
const int mult
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
double result;
|
||||||
|
|
||||||
|
//
|
||||||
|
int period = marketLen * mult;
|
||||||
|
|
||||||
|
//
|
||||||
|
result = iADX(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
period,
|
||||||
|
PRICE_CLOSE,
|
||||||
|
MODE_MAIN,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading Pivot States ...
|
||||||
|
XPvtState GetPVTState(
|
||||||
|
const int bar_index,
|
||||||
|
const int marketLen
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
XPvtState result = {};
|
||||||
|
|
||||||
|
//
|
||||||
|
double hh = GetMarketHighestHigh(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double ho = GetMarketHighestOpen(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double hc = GetMarketHighestClose(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double hl = GetMarketHighestLow(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double ll = GetMarketLowestLow(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double lo = GetMarketLowestOpen(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double lc = GetMarketLowestClose(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double lh = GetMarketLowestHigh(
|
||||||
|
bar_index,
|
||||||
|
marketLen
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filling Result ...
|
||||||
|
//
|
||||||
|
result.hh = hh;
|
||||||
|
result.ho = ho;
|
||||||
|
result.hc = hc;
|
||||||
|
result.hl = hl;
|
||||||
|
|
||||||
|
//
|
||||||
|
result.ll = ll;
|
||||||
|
result.lo = lo;
|
||||||
|
result.lc = lc;
|
||||||
|
result.lh = lh;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Calculate XRange from Market ...
|
||||||
|
static XRState lastXRState;
|
||||||
|
XRState GetXRange(
|
||||||
|
const int bar_index,
|
||||||
|
const int rangeMarketLength
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
XRState result = {};
|
||||||
|
|
||||||
|
//
|
||||||
|
datetime barTime = iTime(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
int marketBarIndex = bar_index + rangeMarketLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Highest High ...
|
||||||
|
//
|
||||||
|
int hhIdx = iHighest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
MODE_HIGH,
|
||||||
|
marketBarIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double hh = iHigh(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
hhIdx
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Lowest Low ...
|
||||||
|
//
|
||||||
|
int llIdx = iLowest(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
MODE_LOW,
|
||||||
|
marketBarIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double ll = iLow(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
llIdx
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (lastXRState.start == 0) {
|
||||||
|
//
|
||||||
|
lastXRState.start = barTime;
|
||||||
|
lastXRState.length = rangeMarketLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
lastXRState.hh = hh;
|
||||||
|
lastXRState.ll = ll;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Middle ...
|
||||||
|
double mid = (hh + ll) / 2;
|
||||||
|
lastXRState.mid = mid;
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
int startBarIndex = iBarShift(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
lastXRState.start
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
if (startBarIndex - bar_index >= rangeMarketLength) {
|
||||||
|
//
|
||||||
|
lastXRState.start = barTime;
|
||||||
|
lastXRState.length = rangeMarketLength;
|
||||||
|
|
||||||
|
//
|
||||||
|
lastXRState.hh = hh;
|
||||||
|
lastXRState.ll = ll;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Middle ...
|
||||||
|
double mid = (hh + ll) / 2;
|
||||||
|
lastXRState.mid = mid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
result = lastXRState;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading XTPowState from Indicatoe ...
|
||||||
|
XTPOWState GetXTPowState(
|
||||||
|
const int bar_index,
|
||||||
|
const int marketLen
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
XTPOWState result = {};
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
double powerUp = 0;
|
||||||
|
double powerDown = 0;
|
||||||
|
double signal = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
string indicatorName = "x-saherelm.xtpow";
|
||||||
|
|
||||||
|
//
|
||||||
|
int pUpIndex = 0;
|
||||||
|
int pDownIndex = 1;
|
||||||
|
int signalIndex = 2;
|
||||||
|
|
||||||
|
//
|
||||||
|
powerUp = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
pUpIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
powerDown = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
pDownIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
signal = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
signalIndex,
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
result.signal = signal;
|
||||||
|
result.powerUp = powerUp;
|
||||||
|
result.powerDown = powerDown;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Reading XRState From Indicator ...
|
||||||
|
XRState ReadXRange(
|
||||||
|
const int bar_index,
|
||||||
|
const int marketLen
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
XRState result = {};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Define Buffer Indexes ...
|
||||||
|
int hhBufferIndex = 0;
|
||||||
|
int llBufferIndex = 1;
|
||||||
|
int midBufferIndex = 2;
|
||||||
|
|
||||||
|
//
|
||||||
|
string indicatorName = "x-saherelm.xrange";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Read Values From XRange Indicator ...
|
||||||
|
|
||||||
|
//
|
||||||
|
double hh = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
hhBufferIndex, // Buffer Index ...
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double ll = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
llBufferIndex, // Buffer Index ...
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
double mid = iCustom(
|
||||||
|
_Symbol,
|
||||||
|
_Period,
|
||||||
|
indicatorName,
|
||||||
|
//
|
||||||
|
// Inputs ...
|
||||||
|
marketLen,
|
||||||
|
//
|
||||||
|
midBufferIndex, // Buffer Index ...
|
||||||
|
bar_index
|
||||||
|
);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Filling Result ...
|
||||||
|
result.hh = hh;
|
||||||
|
result.ll = ll;
|
||||||
|
result.mid = mid;
|
||||||
|
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// END Indicator Reading Data ...
|
||||||
|
//
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,91 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL4 Draw Global Library
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm useful tools and definitions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
#property library
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://www.saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// Log Tag ...
|
||||||
|
static string logTag = "";
|
||||||
|
|
||||||
|
//
|
||||||
|
// Enable or Disable Logging ...
|
||||||
|
static bool enableLogging = false;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Log Messages ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Logging a Message, specified for this EA ...
|
||||||
|
// using provided LogTag ...
|
||||||
|
void LogMessage(string message) {
|
||||||
|
//
|
||||||
|
if (!enableLogging) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
Print(logTag, " > ", message);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// this used for logging series ...
|
||||||
|
void LogSeries(
|
||||||
|
double &series[], // which series to Log ...
|
||||||
|
int length = 0, // number of items to Log, 0 means all ...
|
||||||
|
int skip = 0 // number of items which skip before logging ...
|
||||||
|
) {
|
||||||
|
//
|
||||||
|
string msg = "";
|
||||||
|
|
||||||
|
//
|
||||||
|
int seriesSize = ArraySize(series);
|
||||||
|
if (
|
||||||
|
skip < 0
|
||||||
|
|| length < 0
|
||||||
|
|| seriesSize == 0
|
||||||
|
|| skip > seriesSize
|
||||||
|
|| skip + length > seriesSize
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
length = length == 0 ?
|
||||||
|
seriesSize :
|
||||||
|
length;
|
||||||
|
int start = skip > 1 ?
|
||||||
|
skip - 1 :
|
||||||
|
skip == 1 ?
|
||||||
|
1 :
|
||||||
|
0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Loop through series items ...
|
||||||
|
for (int i = start; i < start + length; i++) {
|
||||||
|
//
|
||||||
|
msg += StringConcatenate(
|
||||||
|
"i[", i, "]: ", series[i], ", "
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
LogMessage(msg);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// End Log Messages ...
|
||||||
|
//
|
||||||
|
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
///////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SaherElm IT Center MQL4 Models Global Library
|
||||||
|
// ---------------------------------------------
|
||||||
|
// saherelm useful tools and definitions ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Maintainer:
|
||||||
|
// ------------
|
||||||
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////
|
||||||
|
#property library
|
||||||
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||||
|
#property link "https://www.saherelm.ir"
|
||||||
|
#property version "1.00"
|
||||||
|
#property strict
|
||||||
|
|
||||||
|
//
|
||||||
|
// START STATIC Variables ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
static int totalSignals = 0;
|
||||||
|
static int totalLongSignals = 0;
|
||||||
|
static int totalShortSignals = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
static double initialBalance = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
static int countedBars = 0;
|
||||||
|
static bool isNewBar = false;
|
||||||
|
static bool isNewDay = false;
|
||||||
|
//
|
||||||
|
// END STATIC Variables ...
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start Models ...
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Signal Providers ...
|
||||||
|
enum ENUM_X_SIGNAL_PROVIDER {
|
||||||
|
X_UNKNOWN_PROVIDER,
|
||||||
|
X_XXX_PROVIDER,
|
||||||
|
X_XR_PROVIDER,
|
||||||
|
X_XTPW_PROVIDER
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// these are different signal types ...
|
||||||
|
enum ENUM_X_SIGNAL_TYPE {
|
||||||
|
X_SIGNAL_NONE,
|
||||||
|
X_SIGNAL_LONG,
|
||||||
|
X_SIGNAL_SHORT,
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Model Market Highs and Lows ...
|
||||||
|
struct XPvtState {
|
||||||
|
//
|
||||||
|
double hh;
|
||||||
|
double ho;
|
||||||
|
double hc;
|
||||||
|
double hl;
|
||||||
|
|
||||||
|
//
|
||||||
|
double ll;
|
||||||
|
double lo;
|
||||||
|
double lc;
|
||||||
|
double lh;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// we Model each signals as this type ...
|
||||||
|
struct XSignal {
|
||||||
|
//
|
||||||
|
// Signal Symbol ...
|
||||||
|
string symbol;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Type ...
|
||||||
|
ENUM_X_SIGNAL_TYPE type;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal ID ...
|
||||||
|
int id;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Ticket Number, when Opening Trade ...
|
||||||
|
int ticket;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Provider ...
|
||||||
|
ENUM_X_SIGNAL_PROVIDER provider;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Target Point ...
|
||||||
|
double tp;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Stop Loss ...
|
||||||
|
double sl;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Entry Price ...
|
||||||
|
double entry;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signalling Time ...
|
||||||
|
datetime time;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal Comments ...
|
||||||
|
string comment;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Signal TAG ...
|
||||||
|
string tag;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// this is Signal Request Response model ...
|
||||||
|
struct XSignalRequest {
|
||||||
|
bool hasSignal;
|
||||||
|
XSignal signal;
|
||||||
|
ENUM_X_SIGNAL_TYPE type;
|
||||||
|
ENUM_X_SIGNAL_PROVIDER provider;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
struct XRState {
|
||||||
|
//
|
||||||
|
datetime start;
|
||||||
|
int length;
|
||||||
|
|
||||||
|
//
|
||||||
|
double hh;
|
||||||
|
double ll;
|
||||||
|
double mid;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
struct XTPOWState {
|
||||||
|
//
|
||||||
|
double powerUp;
|
||||||
|
double powerDown;
|
||||||
|
|
||||||
|
//
|
||||||
|
double signal;
|
||||||
|
};
|
||||||
|
//
|
||||||
|
// End Models ...
|
||||||
|
//
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user