DL7267
Pine Script Scholar
Pine Script Scholar
Posts: 1
Joined: January 16th, 2024
Contact: TradingView Profile

✅HELP NEEDED WITH SCRIPT INPUT...ANY HELP IS APPRECIATED✅

Hey guys, I was wondering if anyone could help me apply this concept to this code. I don't think it to complex, but I just can seem to get it to function properly... any help would be greatly appreciated.

"11. Starting trades reading a custom indicator
Hedging EA is equipped to take trades according to a custom indicator of your choosing, which must follow certain conventions. It must store one of the following constants into a non-drawing but accessible buffer.
- Buy: Store 0 in the buffer
- Sell: Store 1 in the buffer
- Do nothing: Store EMPTY_VALUE in the buffer

By storing one of the following values into a buffer in your indicator, and making Hedging EA to read from it, it will be able to buy, sell and close trades when your custom indicator wants to. Kindly note that, closing trades will only work if there are no recovery trades opened. The indicator is read upon bar closing and the trade session filters applied."

this is the example they proved...

//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 0

//---- constants
#define ShortName "My Indicator"
#define OP_CLOSE_BUY 3
#define OP_CLOSE_SELL 4
#define OP_CLOSE_ALL 5

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

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(1); // We only need one buffer
SetIndexBuffer(0,SignalBuffer); // This is the signal buffer (0)
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int start = 1;
int limit;
int counted_bars = IndicatorCounted();

// check for possible errors
if(counted_bars < 0)
return(-1);

// Iteration Limit
limit = Bars - 1 - counted_bars;

// Iterate all bars from past to present
for(int i = limit; i >= start; i--)
{
// Ignore first bar
if(i >= Bars-1) continue;

// Store empty value first, no action by default
SignalBuffer = EMPTY_VALUE;

// If bullish breakout
if(Close > High[i+1]) SignalBuffer = OP_BUY;

// If bearish breakout
if(Close < Low[i+1]) SignalBuffer = OP_SELL;
}
return(0);
}


And this is the code to which I need to add it...

//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Lime
//---- input parameters
input int InpJawsPeriod=13; // Jaws Period
input int InpJawsShift=8; // Jaws Shift
input int InpTeethPeriod=8; // Teeth Period
input int InpTeethShift=5; // Teeth Shift
input int InpLipsPeriod=5; // Lips Period
input int InpLipsShift=3; // Lips Shift
//---- indicator buffers
double ExtBlueBuffer[];
double ExtRedBuffer[];
double ExtLimeBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
void OnInit(void)
{
IndicatorDigits(Digits);
//---- line shifts when drawing
SetIndexShift(0,InpJawsShift);
SetIndexShift(1,InpTeethShift);
SetIndexShift(2,InpLipsShift);
//---- first positions skipped when drawing
SetIndexDrawBegin(0,InpJawsShift+InpJawsPeriod);
SetIndexDrawBegin(1,InpTeethShift+InpTeethPeriod);
SetIndexDrawBegin(2,InpLipsShift+InpLipsPeriod);
//---- 3 indicator buffers mapping
SetIndexBuffer(0,ExtBlueBuffer);
SetIndexBuffer(1,ExtRedBuffer);
SetIndexBuffer(2,ExtLimeBuffer);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
//---- index labels
SetIndexLabel(0,"Gator Jaws");
SetIndexLabel(1,"Gator Teeth");
SetIndexLabel(2,"Gator Lips");
}
//+------------------------------------------------------------------+
//| Bill Williams' Alligator |
//+------------------------------------------------------------------+
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[])
{
int limit=rates_total-prev_calculated;
//---- main loop
for(int i=0; i<limit; i++)
{
//---- ma_shift set to 0 because SetIndexShift called abowe
ExtBlueBuffer=iMA(NULL,0,InpJawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
ExtRedBuffer=iMA(NULL,0,InpTeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
ExtLimeBuffer=iMA(NULL,0,InpLipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
}
//---- done
return(rates_total);
}
//+------------------------------------------------------------------+

if you could can also tell me how to make a inversed one (so buys are sells and sells are buys) I would appreciate it...I don't think it to complex my brain just is not processing the concept.

Return to “Pine Script Q&A”