IDT_variables
Download scriptThis script is designed to automatically analyze current market conditions and dynamically adjust key trading parameters based on the observed volatility and behavior of the price. Instead of using a "one size fits all" approach, the logic identifies the specific state of the market—whether it is experiencing high-speed movement, a steady trend, or sideways fluctuation—and reconfigures the strategy settings accordingly.
Market Analysis Logic
The script begins by measuring price movement over different timeframes. It specifically looks at:
- Instantaneous Movement: The price range of the very last tick.
- Short-term Movement: The price range over the last 10 minutes.
- Medium-term Movement: The price range over the last 15 minutes.
By comparing these ranges against specific thresholds, the script categorizes the market into one of four states:
- High Volatility (Breakout): Identified by a sudden surge in trading volume combined with significant movement in the latest tick.
- Trending Market: Identified when price movement over the 10-minute period exceeds a specific threshold.
- Sideways Market: Identified when the 10-minute price movement is relatively small, suggesting a lack of clear direction.
- Default State: Used if none of the above specific conditions are met.
Dynamic Parameter Adjustment
Once the market state is identified, the script automatically updates several critical trading variables to suit that environment:
- Profit Targets: Adjusts how much profit the system seeks based on how quickly the market is moving.
- Loss Tolerance: Calculates the "acceptable loss" limit. In trending markets, this is often tied to the actual price range of the last 15 minutes, while in other states, it uses fixed safety limits.
- Order Expiration: Sets a time limit on how long a pending order can remain active before being discarded.
- Risk Management: Determines the maximum percentage of the account balance at risk for any single trade.
- Skip Distance: Defines the minimum "gap" required before the system allows a new entry, helping to prevent over-trading in choppy conditions.
Execution and Integration
After the calculations are complete, the script saves these adjusted values as "Global Variables." This means that other trading robots or components can read these updated settings in real-time. The process is finalized with an audible notification to confirm that the market parameters have been successfully recalculated and synchronized.
//+------------------------------------------------------------------+
//| IDT_variables.mq4 |
//| Copyright © 2004, Globus |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Globus"
#include <stdlib.mqh>
#include <WinUser32.mqh>
//+------------------------------------------------------------------+
//| script "nastaveni globalnich promenych" |
//+------------------------------------------------------------------+
int start()
{
PlaySound("Tick.wav");
// promene
int change=0;
int lasttickscale=MathAbs(iHighest(NULL,PERIOD_M1,MODE_HIGH,1,0)-iLowest(NULL,PERIOD_M1,MODE_LOW,1,0)); //rozsah posledniho ticku
int tenminutes=MathAbs(iHighest(NULL,PERIOD_M1,MODE_HIGH,10,0)-iLowest(NULL,PERIOD_M1,MODE_LOW,10,0)); //rozsah poslednich deseti ticku
int fifteenminutes=MathAbs(iHighest(NULL,PERIOD_M1,MODE_HIGH,15,0)-iLowest(NULL,PERIOD_M1,MODE_LOW,15,0)); //rozsah poslednich deseti ticku
int profit=3; //profit do plusu
int lost=13; //akceptovane ztraty
int expiration=60; //doba v minutach do vyprseni cekajiciho prikazu
double maxrisk=0.02; //maximalni riziko na dany obchod v procentech uctu
double skip=0.0003; //nakup nebo prodej lisici se o dany pocet bodu
//podminky
if (Volume[1]>20 && change==0 && lasttickscale>4) change=1; //splaseny trh
if (change==0 && tenminutes>4) change=2; //trendovy trh
if (change==0 && tenminutes<5) change=3; //pohyb do strany
//hodnoty
switch (change)
{
case 1:
profit=10; //profit do plusu
lost=4; //akceptovane ztraty
expiration=5; //doba v minutach do vyprseni cekajiciho prikazu
maxrisk=0.02; //maximalni riziko na dany obchod v procentech uctu
skip=0.0006; //nakup nebo prodej lisici se o dany pocet bodu
break;
case 2:
profit=4; //profit do plusu
lost=MathRound(fifteenminutes*0.8); //akceptovane ztraty
expiration=15; //doba v minutach do vyprseni cekajiciho prikazu
maxrisk=0.02; //maximalni riziko na dany obchod v procentech uctu
skip=0.0004; //nakup nebo prodej lisici se o dany pocet bodu
if (lost>13 || lost<4) lost=12;
break;
case 3:
profit=2; //profit do plusu
lost=MathRound(tenminutes); //akceptovane ztraty
expiration=60; //doba v minutach do vyprseni cekajiciho prikazu
maxrisk=0.02; //maximalni riziko na dany obchod v procentech uctu
skip=0.0003; //nakup nebo prodej lisici se o dany pocet bodu
if (lost>13 || lost<4) lost=8;
break;
default:
profit=3; //profit do plusu
lost=13; //akceptovane ztraty
expiration=60; //doba v minutach do vyprseni cekajiciho prikazu
maxrisk=0.02; //maximalni riziko na dany obchod v procentech uctu
skip=0.0002; //nakup nebo prodej lisici se o dany pocet bodu
break;
}
Print("Change : ",change," 10/minut : ",tenminutes," 15/minut : ",fifteenminutes);
GlobalVariableSet("profit",profit);
GlobalVariableSet("profit",profit);
GlobalVariableSet("lost",lost);
GlobalVariableSet("expiration",expiration);
GlobalVariableSet("maxrisk",maxrisk);
GlobalVariableSet("skip",skip);
PlaySound("Ok.wav");
return(0);
}
//+------------------------------------------------------------------+
Comments