Attachments forums

List of attachments posted on this forum.


All files on forums: 136800

Re: Something interesting please post here (Metatrader)

besirasani1, Tue Dec 05, 2023 11:07 pm

I have an idea for technical indicator , I used chatgpt to generate some code with help of Malden's deviation channel since i am not a coder. The idea is very simple, and it can be used as support and resistance or entry signal/confirmation. also i think it is important since i have not seen anything like this in my experience with indicator testing:
Lines that connect the close of candles for a specific period with the close of the last closed candle. After this when the new candle forms , these lines can act as a sr/trendlines (but in a different way as you can see), and i think that they are more accurate than trendlines . Also another idea would be if the lines would be extended forward or lets say you add two periods and with that you see the intersection of the candle close lines for those two periods. For now some help would be nice to make the code function properly (when a new candle forms it doesn't move forward) and to add more features if possible (like extended lines, or double periods, or other ideas welcome..)
Here is the code:

//| CustomWhiteLines.mq4 |
//| Copyright 2023, Your Name |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Your Name"
#property version "1.00"
#property strict
#property indicator_chart_window

//--- indicator buffers
double closeBuffer[];

//--- parameters
input int customPeriod = 10;

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
IndicatorBuffers(1);
SetIndexBuffer(0, closeBuffer);
ArraySetAsSeries(closeBuffer, true);

SetIndexLabel(0, "Close Buffer");

return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
static datetime lastTime = 0;

// Check if a new candle has opened
if (time[0] != lastTime)
{
// Delete all existing lines
for (int i = ObjectsTotal(0, OBJ_TREND, 0); i >= 0; i--)
{
string objectName = ObjectName(0, i);
if (StringFind(objectName, "Line_") == 0)
ObjectDelete(0, objectName);
}

lastTime = time[0]; // Move this line after deleting lines
}

int limit = MathMin(rates_total - prev_calculated, customPeriod);

// Copy close prices to buffer
ArraySetAsSeries(closeBuffer, true);
ArrayCopy(closeBuffer, close, 0, prev_calculated, limit);

int lastClosedIndex = 0;

// Find the index of the last closed candle before the open candle
for (int i = limit - 1; i >= 0; i--)
{
if (open == close)
{
lastClosedIndex = i;
break;
}
}

// Draw white lines connecting the close of the first candle to each subsequent candle close
for (int i = 1; i <= lastClosedIndex; i++)
{
// Draw a white line from the close of the first candle to the close of each subsequent candle
ObjectCreate(0, "Line_" + IntegerToString(i), OBJ_TREND, 0, Time[0], closeBuffer[0], Time, closeBuffer);
ObjectSetInteger(0, "Line_" + IntegerToString(i), OBJPROP_COLOR, clrWhite);
ObjectSetInteger(0, "Line_" + IntegerToString(i), OBJPROP_RAY_LEFT, false);
ObjectSetInteger(0, "Line_" + IntegerToString(i), OBJPROP_RAY_RIGHT, false);
}

return(rates_total);
}
//+------------------------------------------------------------------+

Image
All files in topic