Hello, please help me. I want to create a simple bot that can detect dark green, dark red, light green, and light red colors and print them in the log based on the Squeeze indicator.
I tried to write this code but it doesn't respond.
I tried to write this code but it doesn't respond.
Inserted Code
//+------------------------------------------------------------------+
//| SqueezeMomentumPrinter.mq5 |
//| Copyright 2024, YourNameHere. |
//| https://www.yoursite.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, YourNameHere."
#property version "1.00"
#property description "EA for printing Squeeze status"
input int lengthBB = 20;
input double multBB = 2.0;
input int lengthKC = 20;
input double multKC = 1.5;
input ENUM_APPLIED_PRICE priceType = PRICE_CLOSE;
int squeezeHandle;
datetime lastBarTime;
//+------------------------------------------------------------------+
//| Function to detect a new bar |
//+------------------------------------------------------------------+
bool IsNewBar()
{
datetime currentBarTime = iTime(_Symbol, _Period, 0);
if(currentBarTime != lastBarTime)
{
lastBarTime = currentBarTime;
return true;
}
return false;
}
//+------------------------------------------------------------------+
//| Initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
squeezeHandle = iCustom(_Symbol, _Period, "SqueezeMomentumIndicator",
lengthBB, multBB, lengthKC, multKC, priceType);
if(squeezeHandle == INVALID_HANDLE)
{
Alert("Error loading the indicator!");
return(INIT_FAILED);
}
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if(squeezeHandle != INVALID_HANDLE)
IndicatorRelease(squeezeHandle);
}
//+------------------------------------------------------------------+
//| Main tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(IsNewBar())
{
double lineColor[1];
// Read buffer 3 (line color - Squeeze status)
if(CopyBuffer(squeezeHandle, 3, 0, 1, lineColor) < 1)
{
Print("Error reading indicator data!");
return;
}
// Interpret line color
string squeezeStatus;
switch((int)lineColor[0])
{
case 0: squeezeStatus = "Blue (Normal State)"; break;
case 1: squeezeStatus = "Black (Active Squeeze)";
Print(":warning: Warning: Squeeze activated!");
break;
case 2: squeezeStatus = "Gray (End of Squeeze)";
Print(":rotating_light: Signal: Squeeze exit!");
break;
default: squeezeStatus = "Unknown"; break;
}
// Print information
Print("Squeeze Status: ", squeezeStatus, " | Color Code: ", (int)lineColor[0]);
}
}
//+------------------------------------------------------------------+ Attached File(s)