Elliot wave : Wave 3 finder
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Qantar

//@version=4
study("3x finder",overlay=true,max_bars_back=5000)

//eow=rectracment of end of wave x (eowx)
var eow1=0.7, eow2=0.5, eow3=1.618, s=0

//find start of wave 1

N=bar_index+1, LV=lowest(low,N)
LP=valuewhen(low==LV,bar_index,0)

//mark end of wave 1 and 2
if N>LP
    HV=highest(high,N-LP)
    HP=valuewhen(high==HV,bar_index,0)
    R=HV-LV
    FP=HV-eow1*R
    BP=HV-eow2*R
    LV2V=lowest(low,N-HP)
    LV2P=valuewhen(low==LV2V,bar_index,0)
    EXP=LV2V+eow3*R
    if (LV2V<FP)and(LV2V>LV)and(LV2P>HP)
        //label.new(x=LP,y=LV,color=color.red,style=label.style_label_up,textcolor=color.white,text="0")
        if (high>=BP)and(N-1>LV2P)and(close>=BP)
            alert("wave 3 start")
            W0=label.new(x=LP,y=LV,color=color.red,style=label.style_label_up,textcolor=color.white,text="0")
            W1=label.new(x=HP,y=HV,color=color.green,textcolor=color.white,text="1")
            W2=label.new(x=LV2P,y=LV2V,color=color.orange,style=label.style_label_up,textcolor=color.white,text="2")
            label.delete(W0[1])
            label.delete(W1[1])
            label.delete(W2[1])
            TP=LV2V+(1.618*R)
            SL=LV2V
            Line1=line.new(x1=HP,y1=TP,x2=N+100,y2=TP, color=color.green)
            Line2=line.new(x1=HP,y1=SL,x2=N+100,y2=SL, color=color.red)
            Label1=label.new(x=N+100,y=TP,color=color.green,textcolor=color.white,text="Target price = "+tostring(TP))
            Label2=label.new(x=N+100,y=SL,color=color.orange,textcolor=color.white,text="Stop loss = "+tostring(SL))
            line.delete(Line1[1])
            line.delete(Line2[1])
            label.delete(Label1[1])
            label.delete(Label2[1])
            if barstate.islast
                RRR=(TP-high)/(high-SL)
                label.new(x=N-1,y=high,color=color.blue,textcolor=color.white,text="buy \n Risk Reward Ratio = "+tostring(RRR))

fast=ema(close,14)
slow=ema(close,26)
crossover(fast,slow)
barcolor(crossover(fast,slow)? color.blue: crossunder(fast,slow)? color.purple: fast>slow? color.green:color.red) 






