<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Farhad Sanaei on Medium]]></title>
        <description><![CDATA[Stories by Farhad Sanaei on Medium]]></description>
        <link>https://medium.com/@fari_dev?source=rss-7bd937539427------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FETlC4R4oxPwx8sc.</url>
            <title>Stories by Farhad Sanaei on Medium</title>
            <link>https://medium.com/@fari_dev?source=rss-7bd937539427------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 21:58:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fari_dev/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Best Offers App idea - An app that gets all the offers based on your credit or membership cards.]]></title>
            <link>https://medium.com/@fari_dev/best-offers-app-idea-an-app-that-gets-all-the-offers-based-on-your-credit-or-membership-cards-2eb87c4bad72?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/2eb87c4bad72</guid>
            <category><![CDATA[coupon]]></category>
            <category><![CDATA[deal]]></category>
            <category><![CDATA[online-shopping]]></category>
            <category><![CDATA[app-idea]]></category>
            <category><![CDATA[offers]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 12:30:54 GMT</pubDate>
            <atom:updated>2022-03-30T12:30:54.666Z</atom:updated>
            <content:encoded><![CDATA[<p>Best Offers App idea - An app that gets all the offers based on your credit or membership cards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uGimHy5hr99DdXof5aBbVA.jpeg" /></figure><p>In the second episode of the App ideas series, I am planning to write about an App that is actually a wish of mine to have. It should be noted that I know similar apps but they lack many features which I am gonna talk about here.</p><p>Before starting the topic I want to ask you to follow me in medium to support me on my path 🙏💪</p><p>So, as always, let’s get into it.</p><p><strong>The main purpose of the App:</strong></p><p>This App is gonna be a <strong>shopping</strong> <strong>assistant</strong>. You can simply add your credit cards (names only, no credit card number required) and membership cards(names only), and based on those in different situations the app will provide you with the best offers or points that you can get via your credit cards or memberships.</p><p>As a credit cardholder or even a membership cardholder many times I see that my membership allowed me to buy something with a huge discount or get a lot of points for that, but I buy them without knowing those benefits!</p><p>What if you have an App that always opens right before your online shopping payment or on-demand and informs you about the best deals that you are qualified to receive? Wouldn’t it be awesome? You will never miss a deal or extra points anymore 😉</p><p><strong>How User can use it?</strong></p><ol><li>The app will open automatically in online shopping right before the payment. And will check possible coupons or membership benefits that you are qualified to have.</li><li>When a user is looking for a specific product/category (restaurant, bowling, swimming pool and etc…), they can simply open the App and put the name or barcode of the product, or enter the category name. Then app will show the best deals for them based on their memberships and locations</li></ol><p><strong>Collecting data:</strong></p><p>To provide this awesome information, and at the right time, first of all, you need to have that data. This is the most important part that you should never miss and will take most of the time of your development.</p><p>That is really important<br><strong>The more data you have the more powerful you are. And users will like you more and will keep using your APP.</strong></p><p>One of the ways of collecting data is to reward users for providing that information to you. It calls Gamification.</p><p><strong>Collecting data via Gamification:</strong></p><p>Always keep in mind that: <strong>People care about virtual money more than real money. </strong>Users will keep using your App because they earned some virtual money in your App, But if they have some real money in their wallet at some point they might just leave it.</p><p>For instance, if someone has a coupon, good information about a deal, or an offer via a membership card, they can share it, in the App and you will show it to other users. If other users used it and confirmed that it worked then you give points to the user that shared this offer for each +1 received from other users. You do it until users are not adding -1. In that case, it means that the offer wasn’t real or expired.</p><p>Users can exchange their points for coupons from their local shops and use them there.</p><p><strong>Set deal alarm:</strong></p><p>Users can set alarms when they can’t find what they want in the app. So that as soon as there is any new content for them you can notify them via push notification or email.</p><p>In the next parts, I will go more into detail about how can you monetize and earn money via this App.</p><p>Please don&#39;t forget to Subscribe and 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2eb87c4bad72" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rx SwitchMap, Check before dispose]]></title>
            <link>https://towardsdev.com/rx-switchmap-check-before-dispose-6a6469a5b459?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a6469a5b459</guid>
            <category><![CDATA[rxjava]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[switchmap]]></category>
            <category><![CDATA[rxandroid]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 10:42:01 GMT</pubDate>
            <atom:updated>2022-04-01T08:10:02.695Z</atom:updated>
            <content:encoded><![CDATA[<p>Before talking about the solution that I am planning to explain here, let&#39;s talk about SwitchMap and its use cases.</p><h3><strong>Where do we use </strong><strong>SwitchMap :</strong></h3><p>You are probably familiar with Mapor FlatMap. When we want to map our value we use Mapand when we want to map or operate on our Source we use FlatMap .</p><p>What if you want to drop the previous progress and proceed with the new process as soon as a new item is emitted to the list? In that case, you should use SwitchMap</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*ulb3F4bs6pJV8WT85t3h8A.png" /><figcaption>SwithMap</figcaption></figure><p>As you see that as soon as a new item is emitted to the chain the previous process with stop and the new process with replace it.</p><h3>So what is missing here? 🤔</h3><p>Now imagine that in the above picture, A and B contains different values and the value A has more priority. Is there a way to check the process that is in progress a check if they have a high priority value, then apply it to the new request before replacing it with the in-progress process?</p><p><strong>Example:</strong></p><p>We have a list like the following that each item is delivered with a delay. In this list, true value has a priority. It means that if a false value wants to replace a true value, it should take the true value and apply it to itself, then replace the current process.</p><p><strong>And here is what it looks like with </strong><strong>SwitchMap in Kotlin:</strong></p><pre>Observable.just(<br>    1 <em>to </em>true,<br>    200 <em>to </em>true,<br>    3 <em>to </em>false,<br>    210 <em>to </em>true,<br>    2 <em>to </em>false,<br>    190 <em>to </em>false<br>)<br>    .concatMap <strong>{ </strong>(first, second) <strong>-&gt;<br>        </strong>Observable.just(first <em>to </em>second).delay(first.toLong(), TimeUnit.<em>MILLISECONDS</em>)<br>    <strong>}<br>    </strong>.switchMapSingle <strong>{ </strong>pair <strong>-&gt;<br>        </strong>&quot;${pair.first}X -&gt; ${pair.second}&quot;.<em>toSingle</em>()<br>            .delay(pair.first.toLong(), TimeUnit.<em>MILLISECONDS</em>)<br>    <strong>}<br>    </strong>.blockingSubscribe <strong>{<br>        </strong><em>println</em>(<strong>it</strong>)<br>    <strong>}</strong></pre><p>And the result is:</p><pre>1X -&gt; true<br>3X -&gt; false<br>2X -&gt; false<br>190X -&gt; false</pre><p>We do expect to have the following result instead:</p><pre>1X -&gt; true<br>3X -&gt; true<br>2X -&gt; true<br>190X -&gt; false</pre><p>Where when 3 is overriding the 200, it takes the value of 200 which is true . the same as 2 and 210.</p><p><strong>How did I resolve it?</strong></p><p>I created a new SwitchMap extension which will ask the consumer to operate the new value by providing the in-progress value right before overriding the processes.</p><pre>fun &lt;T : Any, R : Any&gt; Observable&lt;T&gt;.switchMapWithInProgressCheck(<br>    mapper: (T) -&gt; Single&lt;out R&gt;,<br>    processValueWithInProgressValue: (T, T) -&gt; T<br>): Observable&lt;R&gt; {<br>    val inProgressBoolean: AtomicReference&lt;T?&gt; = AtomicReference(null)<br><br>    return this.map <strong>{ </strong>value <strong>-&gt;<br>        </strong>val inProgressValue = inProgressBoolean.get()<br>        if (inProgressValue != null) {<br>            processValueWithInProgressValue(inProgressValue, value)<br>        } else {<br>            value<br>        }<br>    <strong>}<br>        </strong>.switchMapSingle <strong>{ </strong>value <strong>-&gt;<br>            </strong>mapper(value).doOnSubscribe <strong>{<br>                </strong>inProgressBoolean.set(value)<br>            <strong>}</strong>.doFinally <strong>{<br>                </strong>inProgressBoolean.set(null)<br>            <strong>}<br>        }<br></strong>}</pre><p><strong>How can you use it?</strong></p><pre>Observable.just(<br>    1 <em>to </em>true,<br>    200 <em>to </em>true,<br>    3 <em>to </em>false,<br>    210 <em>to </em>true,<br>    2 <em>to </em>false,<br>    190 <em>to </em>false<br>)<br>    .concatMap <strong>{ </strong>pair <strong>-&gt;<br>        </strong>Observable.just(pair).delay(pair.first.toLong(), TimeUnit.<em>MILLISECONDS</em>)<br>    <strong>}<br>    </strong>.<em>switchMapWithInProgressCheck</em>&lt;Pair&lt;Int, Boolean&gt;, String&gt;(<br>        mapper = <strong>{ </strong>(first, second) <strong>-&gt;<br>            </strong>&quot;${first}X -&gt; $second&quot;.<em>toSingle</em>()<br>                .delay(first.toLong(), TimeUnit.<em>MILLISECONDS</em>)<br>        <strong>}</strong>,<br>        processValueWithInProgressValue = <strong>{ </strong>inProgress, current <strong>-&gt;<br>            </strong>if (inProgress.second) {<br>                current.first <em>to </em>inProgress.second<br>            } else {<br>                current<br>            }<br>        <strong>}<br>    </strong>)<br>    .blockingSubscribe <strong>{<br>        </strong><em>println</em>(<strong>it</strong>)<br>    <strong>}</strong></pre><p>And the result will be as we expected to have:</p><pre>1X -&gt; true<br>3X -&gt; true<br>2X -&gt; true<br>190X -&gt; false</pre><p>I hope it was useful. Please don&#39;t forget to subscribe and 👏 🙂</p><p>Happy coding</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a6469a5b459" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/rx-switchmap-check-before-dispose-6a6469a5b459">Rx SwitchMap, Check before dispose</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best App/Business Ideas — Financial analyzer App]]></title>
            <link>https://medium.com/@fari_dev/best-app-business-ideas-financial-analyzer-app-36c31757e211?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/36c31757e211</guid>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[monetization]]></category>
            <category><![CDATA[app-idea]]></category>
            <category><![CDATA[financial-planning]]></category>
            <category><![CDATA[expense-management]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Mon, 21 Mar 2022 18:51:15 GMT</pubDate>
            <atom:updated>2022-03-21T19:44:23.972Z</atom:updated>
            <content:encoded><![CDATA[<p>Best App/Business Ideas — Financial analyzer App</p><p>In this article, I am going to explain a <strong>Financial App</strong> that can <strong>analyze</strong> user transactions and provide <strong>improvement suggestions</strong> to <strong>save more</strong> and avoid yearly expenses surprises.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ec3xwHu8MZrv5_CtrAyzGA.jpeg" /></figure><h3><strong>Vocabulary</strong>:</h3><p>Before starting to talk about the idea let&#39;s agree on some vocabulary here to use during the App explanation.</p><p><strong>Saving</strong>: Leftover of each calendar month will go to a separate account/bucket/space,… We call it a Saving account here.</p><p><strong>Monthly expenses</strong>: Expenses that you might or might not have every month. These are expenses that are not constant. Like shopping for food, You can&#39;t say how much exactly you will pay for that and you can&#39;t say that this will happen every month.</p><p><strong>Goals</strong>: In another hand, there are costs that we know when and how much we have to pay. For instance Monthly Internet costs, or monthly/yearly subscriptions. Also, we might have costs that we want to define a goal or limitations for that cost. For instance, imagine that you want to limit yourself to don&#39;t spending more than some amount of money on food shopping And if you spend less, next month you can spend a bit more. Lets call these two types of expenses and spending Goals.</p><blockquote>The app looks simple but it is gonna do magic in the end. So you need a professional designer to don&#39;t make your users confused or disappointed.</blockquote><h3>How it works:</h3><p>User opens the app and login/signup</p><p>It will connect to their bank account and will get all the transactions records.</p><p>Now user should define their Monthly expenses and Goals.</p><p>Then it will come up with some expenses or goals suggestions for each of those transactions and will ask for their confirmation or modification. All those transactions should have an expense or goal type.</p><p>Based on the user’s confirmation or modification, the app will learn and next time will come up with better suggestions, and assigning types based on user choices will be less and less and easier every time.</p><p>Then it will analyze and will show how they are spending their money in graphs.</p><p>And will show them what is wrong with their spending based on a suggestion that AI will provide. The AI will learn about spending types from all the users and for each user will provide different suggestions.</p><p>The AI can suggest some plans, which will make restrictions for better spending and prevent <strong>surprise payments </strong>(like yearly insurance payments) by collecting and preparing for those during the year.</p><p>Anytime in the App users can define or modify goals and define the due payment(s) and due date(s). The App will calculate a safe way and will deduct some amount of money every month to reach their goals.</p><p>The app will be able to estimate the saving of each month before the month ends and also show the real-time amounts of the money in Main, Saving, Monthly expenses, and Goal buckets/accounts.</p><h3>Bonus features:</h3><p>The AI can learn about spending or people and find the best deals around users and based on user’s <strong>shopping habits</strong> provide best suggestion or deals.</p><h3>Monetization:</h3><p>You can make revenue via:</p><ul><li>Corporating with banks and providing extra services for them</li><li>Corporating with banks and promote them in your app and get referral fees</li><li>Advertising related shops/services when they are related to the user. You can check it via the history of transactions of the user. For instance, a user is buying regularly from a specific shop, in case of an event for that shop you can show a special deal of that shop for that specific user.</li><li>Subscription plan. You can provide some extra features for your premium users. Features like connection to a specific bank, showing more detailed analysis, having multiple saving buckets/accounts.</li></ul><h3>Development plan — Time &amp; Cost estimation:</h3><p>As I said before you need a good designer to design your App with the best standards so that your users will understand all the App powers and will not miss anything or you will not confuse them with a bad UI/UX.</p><p>For the implementation of this App, you need to have backend and frontend (mobile and web) developers. You can make it for web and mobile or only for one of them based on your decision.</p><p><strong>MVP Version features:</strong></p><p>Users can log in, connect a bank account, and define expenses types and goals.</p><p>Based on those they can see an analysis for each month</p><p>For this phase, the whole development might take about <strong>6 weeks</strong></p><p><strong>Phase 1 - Simple AI:</strong></p><p>Implementation of smart categorisation via AI.</p><p>In this part, a simple AI will be implemented and will start to collect information and learn based on those.</p><p>In this phase, you can also implement the expense type or goal <strong>smart suggestions</strong> for each transaction.</p><p>This part can take about <strong>4 weeks</strong> to implement.</p><p><strong>Phase 2 - Subscription:</strong></p><p>Implementation of subscription plans, payments, admin panel to make payment confirmation or refund and introducing premium features.</p><p>This part can take about <strong>6 weeks </strong>to implement.</p><p><strong>Phase 3 - Advertisement:</strong></p><p>Add advertisement possibilities, an admin panel to submit and manage ads, and a panel for advertisers to see the ad performance. In this phase, only admins can submit an ad, and advertisers still can’t advertise by themselves.</p><p>This part can take up to <strong>6 weeks</strong> to implement.</p><p>After this, you can start to make more corporations with more banks or focus on providing more useful features for users depending on the user behavior in your app.</p><p>I hope it was useful, Please let me know if you have any questions in the comments. And don&#39;t forget to 👏 and follow to stay up to date with upcoming articles of this series.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36c31757e211" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Best App/Business Ideas series]]></title>
            <link>https://medium.com/@fari_dev/best-app-business-ideas-series-11cb3d87e18f?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/11cb3d87e18f</guid>
            <category><![CDATA[ideas]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[app-idea]]></category>
            <category><![CDATA[app-development]]></category>
            <category><![CDATA[business-ideas]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Mon, 21 Mar 2022 18:01:19 GMT</pubDate>
            <atom:updated>2022-03-21T18:59:36.783Z</atom:updated>
            <content:encoded><![CDATA[<p>Best App/Business Ideas series</p><p>The app market is changing rapidly. App or online services market is not like 5 or 10 years ago. To make it a success you should not think about being first anymore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*42lJDUOtj1tShWIMqw2VrQ.jpeg" /></figure><p>You should have:</p><ul><li>Marketing strategy</li><li>Business plans</li><li>Market research</li><li>Know when and how you want to publish</li><li>Estimating the costs</li><li>And much more</li></ul><p>I have about +15 years of professional experience in this market and in this series, I am planning to share some of my App ideas with their monetization plans and cost &amp; time estimations.</p><p>In each post, I will share and talk about only one idea to be able to go deeper for each of them.</p><p>If you have any questions let me know in the comments and I will try to answer all the questions 💪</p><p>Let&#39;s get into it.</p><p><a href="https://medium.com/@fari_dev/best-app-business-ideas-financial-analyzer-app-36c31757e211">Best App/Business Ideas — Financial analyzer App</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11cb3d87e18f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When is the best time to buy or sell your stocks — Part 1]]></title>
            <link>https://medium.com/@fari_dev/when-is-the-best-time-to-buy-or-sell-your-stocks-part-1-f0a6ea10aec4?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0a6ea10aec4</guid>
            <category><![CDATA[buy-stocks-online]]></category>
            <category><![CDATA[buy-sell-stock]]></category>
            <category><![CDATA[tesla]]></category>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[stocks]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Wed, 23 Sep 2020 15:54:48 GMT</pubDate>
            <atom:updated>2020-09-23T15:54:48.484Z</atom:updated>
            <content:encoded><![CDATA[<h3>When is the best time to buy or sell your stocks — Part 1</h3><p>I am recently checking Tesla’s stocks very closely and analyze it via scripts that I made. For more information regarding what is the script and how I made it, check the following series.</p><p><a href="https://medium.com/@fari_dev/how-i-made-auto-trading-script-part-1-6143ff3d5474">How I made auto trading script — Part 1</a></p><p>Here in this series, I am going to:</p><ul><li>document and share all my findings for when is the best time to buy or sell a stock based on the information that we get from the indicators.</li><li>At the end of this series, I am planning to make a script that will use these findings to inform us about the best times that we can sell or buy a specific stock.</li><li>And then I will(of course 😎) like always write tests for my script to evaluate our findings.</li></ul><p>Great, then let&#39;s get into it.</p><p>The first thing that I need to mention about this series is that I would assume that you are familiar with the basics of indicators because in this series I am not planning to explain in detail what are the indicators that I am using but I will explain that how you can use them.</p><h3><strong>Sell if:</strong></h3><blockquote><strong>RSI is HIGH</strong></blockquote><blockquote><strong>Balance Power is High</strong></blockquote><blockquote><strong>MACD is VERY POSITIVE</strong></blockquote><blockquote><strong>AND only IF RSI starts to decrease</strong></blockquote><p>In this case you need to <strong>sell</strong> <strong>immediately</strong>. and you should not trust your MACD.</p><p>Let me show you an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBSWdZA5_T5755cUdDYMng.png" /></figure><p>As you see in this chart the safest place to sell your stock is exactly when RSI starts to decrease.</p><p>The power is in its max, it means that it might fall any minute, and RSI is showing you an ALL TIME HIGH. a small move in RSI in a negative direction can lead to a crash down. Then the best thing for you in that situation is to sell it immediately.</p><p>Please follow me for getting notifications for the future series and do not forget to 👏</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0a6ea10aec4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I made auto trading script — Part 2]]></title>
            <link>https://medium.com/@fari_dev/how-i-made-auto-trading-script-part-2-ec754d53e547?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec754d53e547</guid>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[autotrader]]></category>
            <category><![CDATA[tesla]]></category>
            <category><![CDATA[macd]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Tue, 22 Sep 2020 21:04:48 GMT</pubDate>
            <atom:updated>2020-09-22T21:05:24.382Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/p/6143ff3d5474?source=post_stats_page-------------------------------------">How I made auto trading script — Part </a>2</h3><p>So let&#39;s see some codes</p><p>Before starting, it needs to be mentioned that all the codes that you will see here are written in python.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PbrALvLrdZgvGbqO.jpg" /></figure><p><strong>Download stock data:</strong></p><p>First of all, what you need is to download stock data. There are many services to provide that, I found yahoo finance API as a very reliable and easy service to fetch this information.</p><p>Following is how you can fetch stock data via yfinance which is a python plugin for fetching yahoo finance API information.</p><pre>yfinance.download(stockName, startDate, endDate, interval = ‘1m’)</pre><p>I would recommend keeping the interval to 1 minute(1m) to have a more accurate MACD.</p><p>It also should be noted that with an interval of 1 minute you cannot query more than 7 days(the difference between startDate and endDate should not be more than 7 days)</p><p><strong>Calculate MACD</strong></p><p>Now based on the stock data that you have you need to calculate the MACD.</p><p>I went through understanding how MACD is calculated and in that way, an article helped a lot and I will share it with you in case you also want to understand how is this calculation happening. <a href="https://fairmontequities.com/how-to-calculate-the-macd/">https://fairmontequities.com/how-to-calculate-the-macd/</a></p><p><strong>There is always a plugin :)</strong></p><p>After a lot of implementations, I found out that there is a python plugin called Talib and it can calculate MACD very easily.</p><p>You can calculate the MACD like following:</p><pre>data[“macd”], data[“macd_signal”], data[“macd_hist”] = talib.MACD(data[‘Close’],fastperiod=12, slowperiod=26, signalperiod=9)</pre><p><strong>When to Buy/Sell?</strong></p><p>Now that we have MACD information, we have to calculate and see when we have to buy or sell our stock.</p><p>There are 5 situations that might happen:</p><ol><li>MACD &lt; Signal AND you did not buy yet -&gt; In this case it means that stock price is decreasing. You need to do nothing and wait</li><li>MACD &lt; Signal AND you already bought a stock -&gt; As stock price is decreasing, in this situation you have to sell your stocks</li><li>MACD &gt; Signal AND you did not buy yet -&gt; As stock price is decreasing, and you still did not buy any stock, in this situation you should buy a new stock</li><li>MACD &gt;Signal AND you already bought a stock -&gt; Stock price is increasing and you already bought a stock. In this situation, you just have to sit back and enjoy increasing the profits in your account :)</li><li>MACD == Signal -&gt; It means that MACD and SIGNAL are crossing each other. You will do nothing in this situation but right after this, you have to check very quickly again and see in which direction MACD and SIGNAL are going and decide about selling/buying.</li></ol><p>Following is how I manage to calculate those situations in my script:</p><pre>orderID = &#39;&#39;<br>if macd - macd_signal &lt; 0 :<br>   if len(orderID) == 0:<br>     print &#39;Dont buy yet&#39;<br>   else:<br>     print &#39;Sell&#39;<br>     orderID = &#39;&#39;<br>  else: <br>   if macd - macd_signal &gt; 0:<br>    if len(orderID) == 0:<br>      print &#39;BUY&#39;<br>      orderID = &#39;&lt;order ID here&gt;&#39;<br>    else:<br>      print &#39;Dont sell yet&#39;<br>   else:<br>     print &#39;Tie, Wait&#39;</pre><p><strong>Let’s run it:</strong></p><p>If you want to simply run your code for a date range then the complete code will be like following:</p><pre>import yfinance<br>import talib</pre><pre>def downloadStockData(stockName= &#39;TL0.DE&#39;, startDate= &#39;2020-9-22&#39;, endDate= &#39;2020-9-23&#39;):<br> return yfinance.download(stockName, startDate, endDate, interval = &#39;1m&#39;)</pre><pre>def calculateMacd(data):<br> data[&quot;macd&quot;], data[&quot;macd_signal&quot;], data[&quot;macd_hist&quot;] = talib.MACD(data[&#39;Close&#39;],fastperiod=12, slowperiod=26, signalperiod=9)<br> return data</pre><pre>def calculateTheProfit(data):<br> orderID = &#39;&#39;<br> for i in range(len(data[&quot;macd&quot;])):<br>  # print(data.index[i], data[&quot;macd&quot;][i] , data[&quot;macd_signal&quot;][i], data[&quot;macd_hist&quot;][i], data[&quot;Close&quot;][i])<br>  # print data.index[i],  data[&quot;macd&quot;][i] - data[&quot;macd_signal&quot;][i]<br>  if data[&quot;macd&quot;][i] - data[&quot;macd_signal&quot;][i] &lt; 0 :<br>   if len(orderID) == 0:<br>    print data.index[i], &#39;Dont buy yet&#39;#, &#39; MACD:&#39;, data[&quot;macd&quot;][i], &#39; Signal:&#39;, data[&quot;macd_signal&quot;][i]<br>   else:<br>    print data.index[i], &#39;Sell&#39;, &#39; Price:&#39;, data[&quot;Close&quot;][i]<br>    orderID = &#39;&#39;<br>  else: <br>   if data[&quot;macd&quot;][i] - data[&quot;macd_signal&quot;][i] &gt; 0:<br>    if len(orderID) == 0:<br>     print data.index[i], &#39;BUY&#39;, &#39; Price:&#39;, data[&quot;Close&quot;][i]<br>     orderID = &#39;Dummy id&#39;<br>    else:<br>     print data.index[i], &#39;Dont sell yet&#39;#, &#39; MACD:&#39;, data[&quot;macd&quot;][i], &#39; Signal:&#39;, data[&quot;macd_signal&quot;][i]<br>   else: <br>    print data.index[i], &#39;Tie, Wait&#39;</pre><pre>lastPrice = 0<br> if len(orderID) != 0:<br>  lastPrice = data[&quot;Close&quot;][len(data[&quot;Close&quot;]) - 1]</pre><pre>stockData = downloadStockData()</pre><pre>stockDataWithMacd = calculateMacd(stockData)</pre><pre>calculateTheProfit(data= stockDataWithMacd)</pre><p>Save the code above in a file(for instance name it macdtest.py) . To run this code you can simply run python macdtest.py in your terminal.</p><p>You can change the dates and stock name to see the results for different stocks and different dates. I would also suggest changing the interval to 1d and use different dates with the difference of (for instance) on year to see prices for every day instead of every minute.</p><p>The output would be something like the following:</p><pre>2020-09-22 14:01:00+02:00 BUY  Price: 363.95001220703125<br>2020-09-22 14:02:00+02:00 Dont sell yet<br>2020-09-22 14:04:00+02:00 Dont sell yet<br>2020-09-22 14:05:00+02:00 Dont sell yet<br>2020-09-22 14:06:00+02:00 Dont sell yet<br>2020-09-22 14:08:00+02:00 Dont sell yet<br>2020-09-22 14:09:00+02:00 Dont sell yet<br>2020-09-22 14:10:00+02:00 Dont sell yet<br>2020-09-22 14:11:00+02:00 Dont sell yet<br>2020-09-22 14:12:00+02:00 Dont sell yet<br>2020-09-22 14:13:00+02:00 Dont sell yet<br>2020-09-22 14:14:00+02:00 Dont sell yet<br>2020-09-22 14:15:00+02:00 Dont sell yet<br>2020-09-22 14:16:00+02:00 Dont sell yet<br>2020-09-22 14:18:00+02:00 Dont sell yet<br>2020-09-22 14:19:00+02:00 Dont sell yet<br>2020-09-22 14:20:00+02:00 Dont sell yet<br>2020-09-22 14:24:00+02:00 Dont sell yet<br>2020-09-22 14:26:00+02:00 Dont sell yet<br>2020-09-22 14:28:00+02:00 Dont sell yet<br>2020-09-22 14:29:00+02:00 Dont sell yet<br>2020-09-22 14:30:00+02:00 Dont sell yet<br>2020-09-22 14:31:00+02:00 Dont sell yet<br>2020-09-22 14:32:00+02:00 Dont sell yet<br>2020-09-22 14:33:00+02:00 Dont sell yet<br>2020-09-22 14:34:00+02:00 Sell  Price: 365.3500061035156<br>2020-09-22 14:35:00+02:00 Dont buy yet<br>2020-09-22 14:37:00+02:00 Dont buy yet</pre><p><strong>What is the next step?</strong></p><p>From what I saw in the output I realized that in some stocks it is not always leading to having a profit if we buy and sell based on MACD.</p><p>So I decided to write some tests for this algorithm to make sure it is at least profitable for most of the time for the stocks that I am trying to buy.</p><p>In the next part, I am going to share my experience with how I tested my code and how <strong>I adjusted it based on my favorite stocks to have maximum profits</strong>.</p><p>Please Clap 👏 , subscribe and share if you liked it ☺️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec754d53e547" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I made auto trading script — Part 1]]></title>
            <link>https://medium.com/@fari_dev/how-i-made-auto-trading-script-part-1-6143ff3d5474?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/6143ff3d5474</guid>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[stock-market]]></category>
            <category><![CDATA[stock-market-tips]]></category>
            <category><![CDATA[stocks]]></category>
            <category><![CDATA[autotrader]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Sun, 20 Sep 2020 20:05:04 GMT</pubDate>
            <atom:updated>2020-09-22T21:10:10.096Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I made auto trading script — Part 1</h3><p>The idea started when I was buying and selling stocks in the market. I realized that I am spending a lot of time refreshing pages and checking prices, queues, news, etc… I started to think that at least some parts of these can be automated.</p><p>As an engineer, I believe that <strong>if something can be automated, it must be automated</strong>. So that I started to made some research to see how people are analyzing stocks. I found out that the most effective calculations/estimations that are widely used among people are RSI and MACD. RSI was more like a short term estimation to me that you can use more when you are buying/selling currencies. As I was more focusing on buying stocks and for a longer time than 1 hour or 1 day(maybe), I thought that MACD was the best option for me to start with.</p><p>So in the beginning I started to check if it really works. One of the stocks that I was really interested in and I was always following was my beloved ‘Tesla’. So I tried to check how MACD was estimating changes for Tesla in the past few days.</p><p>To see those charts I used Yahoo finance, as it was public and fast and I could check it everywhere without login into any accounts.</p><p>Here you can see the latest changes in Tesla(EUR) stock: <a href="https://finance.yahoo.com/chart/TL0.DE">https://finance.yahoo.com/chart/TL0.DE</a></p><p>You can show MACD for stocks by selecting the MACD from indicators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*JbZie9at973MGfwZ9loDHQ.png" /></figure><p>After enabling it you will have a separate view below your stock price that shows your MACD chart</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kZng9NWkvMy-LpG1VekcrQ.png" /></figure><p>In the picture above as you see the chart on the top is the price and below that you see the MACD chart.</p><h3><strong>So what is MACD?</strong></h3><ul><li>Moving Average Convergence Divergence (MACD) is calculated by subtracting the 26-period exponential moving average (EMA) from the 12-period EMA.</li><li>MACD triggers technical signals when it crosses above (to buy) or below (to sell) its signal line.</li><li>The speed of crossovers is also taken as a signal of a market is overbought or oversold.</li><li>MACD helps investors understand whether the bullish or bearish movement in the price is strengthening or weakening.</li></ul><p>As a beginner what you need to know about MACD is that the chart is showing you 2 lines, MACD and Signal lines.</p><p><strong>When Signal is above MACD</strong> -&gt; It means that a stock price is decreasing, Now it is not a good time to buy.</p><p><strong>When MACD is above Signal</strong> -&gt; It means that stock price is increasing and you should not sell your stock now.</p><p><strong>So when should we buy or sell?</strong> Whenever Signal and MACD crossed each other. Imagine that signal is above MACD and suddenly MACD will go cross it and go up. At that moment is the best time to buy the stock as the stock price is gonna increase at that moment.</p><p><strong>Let me show you an example:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Lvh8cyovjJ0zLUlt2xY2g.png" /></figure><p>As you will see in this chart</p><p>At 12:24 MACD said it is time to buy and after that stock price kept increasing</p><p>At 12:48 it said sell it now</p><p>At about 1:03 it said buy now</p><p>And at around 1:40 it said that you need to sell it</p><p>By just following MACD signals for this one hour you could make about 40 EUR of profit by just buying one stock with a price of around 370 EUR.</p><p>More than 11% of profit in just an hour, isn&#39;t that amazing?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/0*DiTWwLZ4eJ3lPJmv.jpg" /></figure><p>Now think how great it would be if you can make all these processes automated</p><p>It seems a really straight forward process and in the second part, I will explain how I automated it and how I tested my automation script.</p><p>You can read part 2 from the following link:</p><p><a href="https://medium.com/@fari_dev/how-i-made-auto-trading-script-part-2-ec754d53e547">How I made auto trading script — Part 2</a></p><p>If you liked it please Clap and Subscribe to get notifications for the next parts</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6143ff3d5474" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Essential requirements for Android developers Part 02 — gradle offline]]></title>
            <link>https://medium.com/@fari_dev/essential-requirements-for-android-developers-part-02-gradle-offline-245606debd20?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/245606debd20</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[essentials]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Fri, 04 Sep 2020 14:56:50 GMT</pubDate>
            <atom:updated>2020-09-04T14:56:50.358Z</atom:updated>
            <content:encoded><![CDATA[<h3>Essential requirements for Android developers Part 02 — gradle offline</h3><p>There were a lot of times that I was complaining about the build time. I am sure that you also did it a looooot :)</p><p>What I figured out is that in some cases, every time that we make a build, gradle is trying to fetch all the libraries again! That would be so time-consuming for us.</p><p>How can we resolve it? What is the solution? <strong>We can cache them and turn gradle to offline</strong>!</p><p>To do that, you need to make one successful build first. Then you click the offline toggle from the gradle window on the right side of your IDE as it showed in the following image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*mKi5xbUYeWwAlW1Cvcu_TQ.png" /><figcaption>Gradle offline toggle in Android Studio</figcaption></figure><p>After that every time that you make a build it will use cached libraries instead of fetching everything again.</p><p>Please be aware that you might need to turn it off only when you make a change in the versions of the libraries that you are using. But again after a successful build, you can turn it on to prevent fetching external libraries 😊</p><p>I hope you enjoyed it and finds it useful. I will keep this series up to date and will add more tricks.</p><p>If you find this useful please subscribe and 👏</p><p>Happy coding 🤓</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=245606debd20" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Essential requirements for Android developers Part 01]]></title>
            <link>https://medium.com/@fari_dev/essential-requirements-for-android-developers-part-01-31c5c46d543e?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/31c5c46d543e</guid>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-studio]]></category>
            <category><![CDATA[heap-size]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Fri, 04 Sep 2020 13:59:29 GMT</pubDate>
            <atom:updated>2020-09-04T14:58:42.808Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>How can we make our Android Studio Faster?</strong></p><p>You probably had times as an Android developer that could not do anything or stuck because your Android studio kept processing and processing and processing ….</p><p>In this series, I am gonna show you how you can set up your environments, projects, and configurations like a pro to decrease all the daily hassles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ofBry8MvdU0zPCqJ" /><figcaption>Photo by <a href="https://unsplash.com/@ninjason?utm_source=medium&amp;utm_medium=referral">Jason Leung</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this first part, I am gonna focus on Memory usage of your Android Studio and show you how you can manage it.</p><p><strong>01) Java heap memory management:</strong></p><p>As you already know Java is consuming a lot of memory in AS and most of the time that lack of memory is slowing down everything on your system.</p><p>My recommendations:</p><ul><li>Make sure that your computer has enough memory(RAM). On my computer, I am using 16GB of RAM and I never faced any issues with AS.</li><li>Configure your AS to use enough memory (based on your project requirements)</li></ul><p><strong>How can we set up AS to use enough memory?</strong></p><p>All that you need to configure is located in a file called studio.vmoptions .</p><p>You can find this file:</p><p>MAC -&gt; Go to AS package contents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D-k90VVGpcn-vO7adlUC-A.png" /></figure><p>The file is located at Contents/bin/studio.vmoptions</p><p>Windows -&gt; File is located at&lt;AS_Install_Folder&gt;/bin/studio.vmoptions</p><p>After opening the file make sure that the file has the following configurations. If it doesn’t have you need to add it. And <strong>make sure that you do not make duplicated configurations in this file,</strong> if you have these configurations already with another value, then just change their values.</p><pre>-Xms2g<br>-Xmx8g<br>-XX:ReservedCodeCacheSize=240m</pre><p>Now the only thing that you need to do is to restart your AS and enjoy its speed 🎉</p><p>I hope you enjoyed it and finds it useful. I will keep this series up to date and will add more tricks.</p><p>If you find this useful please subscribe and 👏</p><p><a href="https://medium.com/@fari_dev/essential-requirements-for-android-developers-part-02-gradle-offline-245606debd20">You can go to the next part of this series from here.</a></p><p>Happy coding 🤓</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31c5c46d543e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to specify a style for a view programmatically in Android]]></title>
            <link>https://towardsdev.com/how-to-specify-a-style-for-a-view-programmatically-in-android-bba8622da173?source=rss-7bd937539427------2</link>
            <guid isPermaLink="false">https://medium.com/p/bba8622da173</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[style]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Farhad Sanaei]]></dc:creator>
            <pubDate>Thu, 28 Feb 2019 12:18:29 GMT</pubDate>
            <atom:updated>2022-04-01T10:17:59.567Z</atom:updated>
            <content:encoded><![CDATA[<p>I was recently looking for a way to set the style for a view programmatically. I found some solutions that I am going to share here with you.</p><h3><strong>Libraries</strong>:</h3><p>Of course, there is always a library for anything that you are looking for :)</p><p>I found the following library useful for changing the style of an existing view:</p><p><a href="https://github.com/airbnb/paris">GitHub - airbnb/paris: Define and apply styles to Android views programmatically</a></p><p>For changing the style with the library you just have to do it like:</p><pre>myView.style(R.style.MyStyle)</pre><h3><strong>Without Libraries:</strong></h3><p>If you are not a fan of adding external libraries to your project(like me) then I can suggest a simple solution. you can still specify a style for your view, but problem is that you have to create your view programmatically and can&#39;t change the style for a view in an XML file.</p><p>So all you have to do is to pass your style to the view while initializing it. like the following:</p><pre>Button(<em>context</em>, <strong>null</strong>, R.style.<em>AppTheme_ButtonPrimary</em>)</pre><p>I realized that there are some issues with styling some views in this way. For instance, this solution doesn&#39;t work with Material Design views(for instance: MaterialButton). For those views, you can use `ContextThemeWrapper`.</p><pre><strong>val </strong>newContext = ContextThemeWrapper(<br>      <em>context</em>,<br>      R.style.<em>AppTheme_ButtonPrimary<br></em>)<br><br><strong>val button </strong>= MaterialButton(newContext)</pre><p>I hope this article helps to resolve some issues. And please comment if you know some more solutions regarding the topic.</p><p>Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bba8622da173" width="1" height="1" alt=""><hr><p><a href="https://towardsdev.com/how-to-specify-a-style-for-a-view-programmatically-in-android-bba8622da173">How to specify a style for a view programmatically in Android</a> was originally published in <a href="https://towardsdev.com/">Towards Dev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>