gj_sh_1H_gbpJPY
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © fujimoto_ka

//@version=5
strategy("gj_sh_1H_gbpJPY",commission_type = strategy.commission.cash_per_contract,commission_value = 0.009,default_qty_value = 1000, overlay=true, margin_long=100, margin_short=100)

length = input.int(20, minval=1)
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2, minval=0.001, maxval=50, title="StdDev")

ma(source, length, _type) =>
    switch _type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
offset = input.int(0, "Offset", minval = -500, maxval = 500)
plot(basis, "Basis", color=#FF6D00, offset = offset)
p1 = plot(upper, "Upper", color=#2962FF, offset = offset)
p2 = plot(lower, "Lower", color=#2962FF, offset = offset)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

emano = ta.ema(close ,800)
emano4 = ta.ema(close ,3200)
plot( emano,color = color.red  )
plot( emano4,color = color.rgb(12, 8, 8)  )


ema_macd1 =ta.ema(close ,12)
ema_macd2 =ta.ema(close ,26)
ema_macd3 =ta.ema(close ,12*16)
ema_macd4 =ta.ema(close ,26*16)
ema_macd =ta.ema(close ,4)
ema_macd0 =ta.ema(close ,9)
plot( ema_macd,color = color.rgb(143, 164, 4)  )
plot( ema_macd0,color = color.rgb(131, 136, 3)  )
plot( ema_macd1,color = color.rgb(15, 203, 5)  )
plot( ema_macd2,color = color.rgb(45, 170, 3)  )
plot( ema_macd3,color = color.rgb(82, 255, 243)  )
plot( ema_macd4,color = color.rgb(18, 224, 243)  )

macd_short =  ema_macd1 < ema_macd2
macd_long =  ema_macd1 > ema_macd2
macd_short_2 =  ema_macd3 < ema_macd4
macd_long_2 =  ema_macd3 > ema_macd4
macd_short_For_tutumi =  ema_macd1 < ema_macd2 + 0.01

macd_trend  =ta.ema(close[1] ,12) - ema_macd1 < 0 ? true:false
macd_trend2  =ta.ema(close[1] ,12*16) - ema_macd3 < 0 ? true:false


//陰線ツツミ　ショート
isTUTUMI_1 =   open[0] - close[0]  >= 0.1 and high[1] < high[0] and low[1] > low[0] and close[0] < open[0] and open[1] >= close[0]    ?  true:na
//上髭残しショート　一つ前陰線
isTUTUMI_7 =   open[1] - close[1]  >= 0 and open[0] - close[0]  >= 0 and high[1] > close[0] and open[1] > low[0] and open[1] >= close[0] and close[1] >= close[0]   and  open[1] < high[0]   ?  true:na
//上髭残しショート　一つ前陽線
isTUTUMI_8 =   open[1] - close[1]  <= 0 and open[0] - close[0]  >= 0 and high[1] > close[0] and open[1] > low[0] and open[1] >= close[0] and close[1] >= close[0]      ?  true:na


//陽線
isTUTUMI_2 =   open[0] - close[0]  <= 0 and high[1] > high[0] and low[1] > low[0] and close[0] > open[0] and close[0] > open[1]  ?  true:na
//陽線
isTUTUMI_3 =   open[0] - close[0]  <= 0 and high[1] < close[0] and open[1] > low[0] and close[1] > open[0]  ?  true:na
//陽線ツツミ　一つ前陰線
isTUTUMI_4 =   open[1] - close[1]  >= 0 and open[0] - close[0]  <= 0 and high[1] < close[0] and open[1] > low[0]   ?  true:na
//上髭残しロング 一つ前が陰線
isTUTUMI_5 =   open[1] - close[1]  >= 0 and open[0] - close[0]  <= 0 and high[1] > close[0] and open[1] > low[0] and open[1] <= close[0] and close[1] <= close[0]   ?  true:na
//した髭残し陽線ロング　一つ前陽線
isTUTUMI_6 =   open[1] - close[1]  <= 0 and open[0] - close[0]  <= 0 and high[1] < close[0] and open[1] >= low[0] and open[1] <= close[0] and close[1] <= close[0]   ?  true:na
//した髭残し陽線ロング　一つ前陽線 一つ前のhighがcloseより高い
isTUTUMI_9 =   open[1] - close[1]  <= 0 and open[0] - close[0]  <= 0 and high[1] > close[0] and open[1] >= low[0] and open[1] <= close[0] and close[1] <= close[0]   ?  true:na


isTUTUMI = isTUTUMI_1 
isTUTUMI_short = (close[0] > emano) 
isTUTUMI_long = (close[0] < emano) 
isTUTUMI_long_without_ema =  isTUTUMI_2 
isTUTUMI_short_without_ema = isTUTUMI_1 


//=====================================================================
val_min_1H	=	ta.lowest(low,10)
val_max_1H	=	ta.highest(high ,12 )
val_min_4H	=	ta.lowest(low ,22 )

val_min_5m	=	math.min(low[	0	],low[	1	],low[	2	])																			
val_max_5m	=	math.max(high[	0	],high[	1	],high[	2	])	


val_min_0	=	math.min(low[	1	],low[	2	],low[	3	],low[	4	],low[	5	],low[	6	],low[	7	],low[	8	],low[	9	],low[	10	],low[	11	],low[	12	],low[	13	],low[	14	],low[	15	],low[	16	],low[	17	],low[	18	],low[	19	],low[	20	],low[	21	],low[	22	],low[	23	],low[	24	],low[	25	],low[	26	],low[	27	],low[	28	],low[	29	],low[	30	],low[	31	],low[	32	],low[	33	],low[	34	],low[	35	],low[	36	],low[	37	],low[	38	],low[	39	],low[	40	],low[	41	],low[	42	],low[	43	],low[	44	],low[	45	],low[	46	],low[	47	],low[	48	],low[	49	],low[	50	],low[	51	],low[	52	],low[	53	],low[	54	],low[	55	],low[	56	],low[	57	],low[	58	],low[	59	],low[	60	],low[	61	],low[	62	],low[	63	],low[	64	],low[	65	],low[	66	],low[	67	],low[	68	],low[	69	],low[	70	],low[	71	],low[	72	],low[	73	],low[	74	],low[	75	],low[	76	],low[	77	],low[	78	],low[	79	],low[	80	],low[	81	],low[	82	],low[	83	],low[	84	],low[	85	],low[	86	],low[	87	],low[	88	],low[	89	],low[	90	],low[	91	],low[	92	],low[	93	],low[	94	],low[	95	],low[	96	])																			
val_max_0	=	math.max(high[	1	],high[	2	],high[	3	],high[	4	],high[	5	],high[	6	],high[	7	],high[	8	],high[	9	],high[	10	],high[	11	],high[	12	],high[	13	],high[	14	],high[	15	],high[	16	],high[	17	],high[	18	],high[	19	],high[	20	],high[	21	],high[	22	],high[	23	],high[	24	],high[	25	],high[	26	],high[	27	],high[	28	],high[	29	],high[	30	],high[	31	],high[	32	],high[	33	],high[	34	],high[	35	],high[	36	],high[	37	],high[	38	],high[	39	],high[	40	],high[	41	],high[	42	],high[	43	],high[	44	],high[	45	],high[	46	],high[	47	],high[	48	],high[	49	],high[	50	],high[	51	],high[	52	],high[	53	],high[	54	],high[	55	],high[	56	],high[	57	],high[	58	],high[	59	],high[	60	],high[	61	],high[	62	],high[	63	],high[	64	],high[	65	],high[	66	],high[	67	],high[	68	],high[	69	],high[	70	],high[	71	],high[	72	],high[	73	],high[	74	],high[	75	],high[	76	],high[	77	],high[	78	],high[	79	],high[	80	],high[	81	],high[	82	],high[	83	],high[	84	],high[	85	],high[	86	],high[	87	],high[	88	],high[	89	],high[	90	],high[	91	],high[	92	],high[	93	],high[	94	],high[	95	],high[	96	])																			
val_min_1	=	math.min(low[	97	],low[	98	],low[	99	],low[	100	],low[	101	],low[	102	],low[	103	],low[	104	],low[	105	],low[	106	],low[	107	],low[	108	],low[	109	],low[	110	],low[	111	],low[	112	],low[	113	],low[	114	],low[	115	],low[	116	],low[	117	],low[	118	],low[	119	],low[	120	],low[	121	],low[	122	],low[	123	],low[	124	],low[	125	],low[	126	],low[	127	],low[	128	],low[	129	],low[	130	],low[	131	],low[	132	],low[	133	],low[	134	],low[	135	],low[	136	],low[	137	],low[	138	],low[	139	],low[	140	],low[	141	],low[	142	],low[	143	],low[	144	],low[	145	],low[	146	],low[	147	],low[	148	],low[	149	],low[	150	],low[	151	],low[	152	],low[	153	],low[	154	],low[	155	],low[	156	],low[	157	],low[	158	],low[	159	],low[	160	],low[	161	],low[	162	],low[	163	],low[	164	],low[	165	],low[	166	],low[	167	],low[	168	],low[	169	],low[	170	],low[	171	],low[	172	],low[	173	],low[	174	],low[	175	],low[	176	],low[	177	],low[	178	],low[	179	],low[	180	],low[	181	],low[	182	],low[	183	],low[	184	],low[	185	],low[	186	],low[	187	],low[	188	],low[	189	],low[	190	],low[	191	],low[	192	])																			
val_max_1	=	math.max(high[	97	],high[	98	],high[	99	],high[	100	],high[	101	],high[	102	],high[	103	],high[	104	],high[	105	],high[	106	],high[	107	],high[	108	],high[	109	],high[	110	],high[	111	],high[	112	],high[	113	],high[	114	],high[	115	],high[	116	],high[	117	],high[	118	],high[	119	],high[	120	],high[	121	],high[	122	],high[	123	],high[	124	],high[	125	],high[	126	],high[	127	],high[	128	],high[	129	],high[	130	],high[	131	],high[	132	],high[	133	],high[	134	],high[	135	],high[	136	],high[	137	],high[	138	],high[	139	],high[	140	],high[	141	],high[	142	],high[	143	],high[	144	],high[	145	],high[	146	],high[	147	],high[	148	],high[	149	],high[	150	],high[	151	],high[	152	],high[	153	],high[	154	],high[	155	],high[	156	],high[	157	],high[	158	],high[	159	],high[	160	],high[	161	],high[	162	],high[	163	],high[	164	],high[	165	],high[	166	],high[	167	],high[	168	],high[	169	],high[	170	],high[	171	],high[	172	],high[	173	],high[	174	],high[	175	],high[	176	],high[	177	],high[	178	],high[	179	],high[	180	],high[	181	],high[	182	],high[	183	],high[	184	],high[	185	],high[	186	],high[	187	],high[	188	],high[	189	],high[	190	],high[	191	],high[	192	])																			
val_min_2	=	math.min(low[	193	],low[	194	],low[	195	],low[	196	],low[	197	],low[	198	],low[	199	],low[	200	],low[	201	],low[	202	],low[	203	],low[	204	],low[	205	],low[	206	],low[	207	],low[	208	],low[	209	],low[	210	],low[	211	],low[	212	],low[	213	],low[	214	],low[	215	],low[	216	],low[	217	],low[	218	],low[	219	],low[	220	],low[	221	],low[	222	],low[	223	],low[	224	],low[	225	],low[	226	],low[	227	],low[	228	],low[	229	],low[	230	],low[	231	],low[	232	],low[	233	],low[	234	],low[	235	],low[	236	],low[	237	],low[	238	],low[	239	],low[	240	],low[	241	],low[	242	],low[	243	],low[	244	],low[	245	],low[	246	],low[	247	],low[	248	],low[	249	],low[	250	],low[	251	],low[	252	],low[	253	],low[	254	],low[	255	],low[	256	],low[	257	],low[	258	],low[	259	],low[	260	],low[	261	],low[	262	],low[	263	],low[	264	],low[	265	],low[	266	],low[	267	],low[	268	],low[	269	],low[	270	],low[	271	],low[	272	],low[	273	],low[	274	],low[	275	],low[	276	],low[	277	],low[	278	],low[	279	],low[	280	],low[	281	],low[	282	],low[	283	],low[	284	],low[	285	],low[	286	],low[	287	],low[	288	])																			
val_max_2	=	math.max(high[	193	],high[	194	],high[	195	],high[	196	],high[	197	],high[	198	],high[	199	],high[	200	],high[	201	],high[	202	],high[	203	],high[	204	],high[	205	],high[	206	],high[	207	],high[	208	],high[	209	],high[	210	],high[	211	],high[	212	],high[	213	],high[	214	],high[	215	],high[	216	],high[	217	],high[	218	],high[	219	],high[	220	],high[	221	],high[	222	],high[	223	],high[	224	],high[	225	],high[	226	],high[	227	],high[	228	],high[	229	],high[	230	],high[	231	],high[	232	],high[	233	],high[	234	],high[	235	],high[	236	],high[	237	],high[	238	],high[	239	],high[	240	],high[	241	],high[	242	],high[	243	],high[	244	],high[	245	],high[	246	],high[	247	],high[	248	],high[	249	],high[	250	],high[	251	],high[	252	],high[	253	],high[	254	],high[	255	],high[	256	],high[	257	],high[	258	],high[	259	],high[	260	],high[	261	],high[	262	],high[	263	],high[	264	],high[	265	],high[	266	],high[	267	],high[	268	],high[	269	],high[	270	],high[	271	],high[	272	],high[	273	],high[	274	],high[	275	],high[	276	],high[	277	],high[	278	],high[	279	],high[	280	],high[	281	],high[	282	],high[	283	],high[	284	],high[	285	],high[	286	],high[	287	],high[	288	])																			
val_min_3	=	math.min(low[	289	],low[	290	],low[	291	],low[	292	],low[	293	],low[	294	],low[	295	],low[	296	],low[	297	],low[	298	],low[	299	],low[	300	],low[	301	],low[	302	],low[	303	],low[	304	],low[	305	],low[	306	],low[	307	],low[	308	],low[	309	],low[	310	],low[	311	],low[	312	],low[	313	],low[	314	],low[	315	],low[	316	],low[	317	],low[	318	],low[	319	],low[	320	],low[	321	],low[	322	],low[	323	],low[	324	],low[	325	],low[	326	],low[	327	],low[	328	],low[	329	],low[	330	],low[	331	],low[	332	],low[	333	],low[	334	],low[	335	],low[	336	],low[	337	],low[	338	],low[	339	],low[	340	],low[	341	],low[	342	],low[	343	],low[	344	],low[	345	],low[	346	],low[	347	],low[	348	],low[	349	],low[	350	],low[	351	],low[	352	],low[	353	],low[	354	],low[	355	],low[	356	],low[	357	],low[	358	],low[	359	],low[	360	],low[	361	],low[	362	],low[	363	],low[	364	],low[	365	],low[	366	],low[	367	],low[	368	],low[	369	],low[	370	],low[	371	],low[	372	],low[	373	],low[	374	],low[	375	],low[	376	],low[	377	],low[	378	],low[	379	],low[	380	],low[	381	],low[	382	],low[	383	],low[	384	])																			
val_max_3	=	math.max(high[	289	],high[	290	],high[	291	],high[	292	],high[	293	],high[	294	],high[	295	],high[	296	],high[	297	],high[	298	],high[	299	],high[	300	],high[	301	],high[	302	],high[	303	],high[	304	],high[	305	],high[	306	],high[	307	],high[	308	],high[	309	],high[	310	],high[	311	],high[	312	],high[	313	],high[	314	],high[	315	],high[	316	],high[	317	],high[	318	],high[	319	],high[	320	],high[	321	],high[	322	],high[	323	],high[	324	],high[	325	],high[	326	],high[	327	],high[	328	],high[	329	],high[	330	],high[	331	],high[	332	],high[	333	],high[	334	],high[	335	],high[	336	],high[	337	],high[	338	],high[	339	],high[	340	],high[	341	],high[	342	],high[	343	],high[	344	],high[	345	],high[	346	],high[	347	],high[	348	],high[	349	],high[	350	],high[	351	],high[	352	],high[	353	],high[	354	],high[	355	],high[	356	],high[	357	],high[	358	],high[	359	],high[	360	],high[	361	],high[	362	],high[	363	],high[	364	],high[	365	],high[	366	],high[	367	],high[	368	],high[	369	],high[	370	],high[	371	],high[	372	],high[	373	],high[	374	],high[	375	],high[	376	],high[	377	],high[	378	],high[	379	],high[	380	],high[	381	],high[	382	],high[	383	],high[	384	])																			
val_min_4	=	math.min(low[	385	],low[	386	],low[	387	],low[	388	],low[	389	],low[	390	],low[	391	],low[	392	],low[	393	],low[	394	],low[	395	],low[	396	],low[	397	],low[	398	],low[	399	],low[	400	],low[	401	],low[	402	],low[	403	],low[	404	],low[	405	],low[	406	],low[	407	],low[	408	],low[	409	],low[	410	],low[	411	],low[	412	],low[	413	],low[	414	],low[	415	],low[	416	],low[	417	],low[	418	],low[	419	],low[	420	],low[	421	],low[	422	],low[	423	],low[	424	],low[	425	],low[	426	],low[	427	],low[	428	],low[	429	],low[	430	],low[	431	],low[	432	],low[	433	],low[	434	],low[	435	],low[	436	],low[	437	],low[	438	],low[	439	],low[	440	],low[	441	],low[	442	],low[	443	],low[	444	],low[	445	],low[	446	],low[	447	],low[	448	],low[	449	],low[	450	],low[	451	],low[	452	],low[	453	],low[	454	],low[	455	],low[	456	],low[	457	],low[	458	],low[	459	],low[	460	],low[	461	],low[	462	],low[	463	],low[	464	],low[	465	],low[	466	],low[	467	],low[	468	],low[	469	],low[	470	],low[	471	],low[	472	],low[	473	],low[	474	],low[	475	],low[	476	],low[	477	],low[	478	],low[	479	],low[	480	])																			
val_max_4	=	math.max(high[	385	],high[	386	],high[	387	],high[	388	],high[	389	],high[	390	],high[	391	],high[	392	],high[	393	],high[	394	],high[	395	],high[	396	],high[	397	],high[	398	],high[	399	],high[	400	],high[	401	],high[	402	],high[	403	],high[	404	],high[	405	],high[	406	],high[	407	],high[	408	],high[	409	],high[	410	],high[	411	],high[	412	],high[	413	],high[	414	],high[	415	],high[	416	],high[	417	],high[	418	],high[	419	],high[	420	],high[	421	],high[	422	],high[	423	],high[	424	],high[	425	],high[	426	],high[	427	],high[	428	],high[	429	],high[	430	],high[	431	],high[	432	],high[	433	],high[	434	],high[	435	],high[	436	],high[	437	],high[	438	],high[	439	],high[	440	],high[	441	],high[	442	],high[	443	],high[	444	],high[	445	],high[	446	],high[	447	],high[	448	],high[	449	],high[	450	],high[	451	],high[	452	],high[	453	],high[	454	],high[	455	],high[	456	],high[	457	],high[	458	],high[	459	],high[	460	],high[	461	],high[	462	],high[	463	],high[	464	],high[	465	],high[	466	],high[	467	],high[	468	],high[	469	],high[	470	],high[	471	],high[	472	],high[	473	],high[	474	],high[	475	],high[	476	],high[	477	],high[	478	],high[	479	],high[	480	])																			
dif_min_max_3	=math.abs(	val_max_3	-	val_min_3	)																																																																																																																																																																																																																
dif_min_max_1	=math.abs(	val_max_1	-	val_min_1	)																																																																																																																																																																																																																
dif_min_max_0	=math.abs(	val_max_0	-	val_min_0	)																																																																																																																																																																																																																
dif_min_max_4	=math.abs(	val_max_4	-	val_min_4	)																																																																																																																																																																																																																
dif_min_max_2	=math.abs(	val_max_2	-	val_min_2	)																																																																																																																																																																																																																

dif_max_min = math.abs(	dif_min_max_4 + dif_min_max_0+dif_min_max_1+dif_min_max_2+dif_min_max_3)/5*1.3

week_nehaba_ave_up =(dif_min_max_0 > dif_max_min)

plotchar(week_nehaba_ave_up,location = location.top,char = '周',size = size.tiny,color =color.rgb(105, 248, 246)  )

haba = 0.4
now_max_condition_1H = (val_max_1H - close[0]) < 0.2
no_near_big_down = ((val_max_1H - val_min_1H) < haba)
near_min_50 = ( close[0] - val_min_4H) > 0.3
near_max_within_30 =(val_max_1H - close[0] ) < 0.2


plotchar(near_max_within_30 ,location = location.top,char = '三',size = size.tiny,color =color.rgb(234, 43, 13)  )
plotchar(near_min_50 ,location = location.bottom,char = '三',size = size.tiny,color =color.rgb(237, 35, 12)  )

kiriage = low[1]<low[0]
kirisage = high[1]>high[0]
// plotchar(kirisage,location = location.top,char = '♪',size = size.tiny,color =color.rgb(8, 10, 10)  )
// plotchar(kiriage,location = location.bottom,char = '♪',size = size.tiny,color =color.rgb(8, 10, 10)  )


close_Without_lower = (lower > val_min_5m)
close_Without_uper = (upper < val_max_5m)
// plotchar(close_Without_lower,location = location.bottom,char = 'w',size = size.tiny,color =color.rgb(105, 248, 246))


barcolor(isTUTUMI and week_nehaba_ave_up ? color.rgb(255, 235, 59, 64) : na)

hr_25 = hour == 18  ?  true:false

hr_0 = hour == 0  ?  true:false
hr_1 = hour == 12  ?  true:false
hr_2 = hour == 13  ?  true:false
hr_3 = hour == 3  ?  true:false
hr_14 = hour == 14  ?  true:false
hr_15 = hour == 2  ?  true:false
hr_16 = hour == 3  ?  true:false
hr_17 = hour == 4  ?  true:false
hr_18 = hour == 5  ?  true:false
hr_19 = hour == 6  ?  true:false

hr_9 = hour == 9  ?  true:false
hr_10 = hour == 10  ?  true:false
hr_11 = hour == 11  ?  true:false
hr_12 = hour == 12  ?  true:false
hr_13 = hour == 13  ?  true:false
hr_20 = hour == 20  ?  true:false
hr_21 = hour == 8  ?  true:false
hr_24 = hour == 24  ?  true:false
hr_22 = hour == 16  ?  true:false
hr_23 = hour == 23  ?  true:false
min_0 = minute == 0
min_15 = minute == 15
min_30 = minute == 30
min_45  = minute == 45

loss_val = val_max_1H - close[0]
profit_val = 50

bgcolor(hr_23? color.rgb(248, 163, 229, 85)  : na)

longCondition =  isTUTUMI_short    and macd_long and near_min_50  and macd_short_2
plotchar(longCondition ,location = location.abovebar,char = 'S',size = size.tiny,color =color.rgb(249, 23, 7)  )
longCondition2 = close_Without_lower   and macd_long and macd_short_2
plotchar(longCondition2 ,location = location.abovebar,char = 'S',size = size.tiny,color =color.rgb(7, 31, 249)  )
if (longCondition or longCondition2)
    if(hr_20)
        strategy.entry("My Entry Id_9", strategy.short,comment = "9EN")
 